Completed
Push — master ( aa44e9...fa84e5 )
by Ralf
90:14 queued 73:21
created
api/src/Json/Response.php 4 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -180,7 +180,6 @@  discard block
 block discarded – undo
180 180
 	/**
181 181
 	 * Init responseArray
182 182
 	 *
183
-	 * @param array $arr
184 183
 	 * @return array previous content
185 184
 	 */
186 185
 	public function initResponseArray()
@@ -264,7 +263,7 @@  discard block
 block discarded – undo
264 263
 	 *
265 264
 	 * @param midex $var
266 265
 	 * @param string $prefix =''
267
-	 * @return mixed
266
+	 * @return midex|null
268 267
 	 */
269 268
 	public static function fix_content($var, $prefix='')
270 269
 	{
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -242,13 +242,13 @@
 block discarded – undo
242 242
 		if ($ret === false && ($err = json_last_error()))
243 243
 		{
244 244
 			static $json_err2str = array(
245
-	        	JSON_ERROR_NONE => 'No errors',
246
-	        	JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
247
-	        	JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
248
-	        	JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
249
-	        	JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
250
-	        	JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
251
-	        );
245
+				JSON_ERROR_NONE => 'No errors',
246
+				JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
247
+				JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
248
+				JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
249
+				JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
250
+				JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
251
+			);
252 252
 			error_log(__METHOD__.'('.array2string($var).') json_last_error()='.$err.'='.$json_err2str[$err]);
253 253
 
254 254
 			if (($var = self::fix_content($var)))
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 		/* Wrap the result array into a parent "response" Object */
227 227
 		$res = array('response' => $inst->responseArray);
228 228
 
229
-		return self::json_encode($res);	//PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
229
+		return self::json_encode($res); //PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
230 230
 	}
231 231
 
232 232
 	/**
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 	 * @param string $prefix =''
267 267
 	 * @return mixed
268 268
 	 */
269
-	public static function fix_content($var, $prefix='')
269
+	public static function fix_content($var, $prefix = '')
270 270
 	{
271 271
 		if (json_encode($var) !== false) return $var;
272 272
 
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 		}
278 278
 		else
279 279
 		{
280
-			foreach($var as $name => &$value)
280
+			foreach ($var as $name => &$value)
281 281
 			{
282 282
 				$value = self::fix_content($value, $prefix ? $prefix.'['.$name.']' : $name);
283 283
 			}
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -268,7 +268,10 @@
 block discarded – undo
268 268
 	 */
269 269
 	public static function fix_content($var, $prefix='')
270 270
 	{
271
-		if (json_encode($var) !== false) return $var;
271
+		if (json_encode($var) !== false)
272
+		{
273
+			return $var;
274
+		}
272 275
 
273 276
 		if (is_scalar($var))
274 277
 		{
Please login to merge, or discard this patch.
api/src/Ldap.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	/**
100 100
 	 * Returns information about connected ldap server
101 101
 	 *
102
-	 * @return Ldap\ServerInfo|null
102
+	 * @return Ldap\ServerInfo
103 103
 	 */
104 104
 	function getLDAPServerInfo()
105 105
 	{
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 * @param string $host ldap host
218 218
 	 * @param string $dn ldap dn
219 219
 	 * @param string $passwd ldap pw
220
-	 * @return resource|boolean resource from ldap_connect() or false on error
220
+	 * @return boolean resource from ldap_connect() or false on error
221 221
 	 */
222 222
 	private function _connect($host, $dn, $passwd)
223 223
 	{
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,17 +31,17 @@
 block discarded – undo
31 31
 class Ldap
32 32
 {
33 33
 	/**
34
-	* Holds the LDAP link identifier
35
-	*
36
-	* @var resource $ds
37
-	*/
34
+	 * Holds the LDAP link identifier
35
+	 *
36
+	 * @var resource $ds
37
+	 */
38 38
 	var $ds;
39 39
 
40 40
 	/**
41
-	* Holds the detected information about the connected ldap server
42
-	*
43
-	* @var Ldap\ServerInfo $ldapserverinfo
44
-	*/
41
+	 * Holds the detected information about the connected ldap server
42
+	 *
43
+	 * @var Ldap\ServerInfo $ldapserverinfo
44
+	 */
45 45
 	var $ldapserverinfo;
46 46
 
47 47
 	/**
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -49,14 +49,14 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @var boolean $exception_on_error
51 51
 	 */
52
-	var $exception_on_error=false;
52
+	var $exception_on_error = false;
53 53
 
54 54
 	/**
55 55
 	 * Constructor
56 56
 	 *
57 57
 	 * @param boolean $exception_on_error =false true: throw Exceptions in ldapConnect instead of echoing error and returning false
58 58
 	 */
59
-	function __construct($exception_on_error=false)
59
+	function __construct($exception_on_error = false)
60 60
 	{
61 61
 		$this->exception_on_error = $exception_on_error;
62 62
 		$this->restoreSessionData();
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @throws Exception\AssertingFailed 'LDAP support unavailable!' (no ldap extension)
84 84
 	 * @throws Exception\NoPermission if bind fails
85 85
 	 */
86
-	public static function factory($ressource=true, $host='', $dn='', $passwd='')
86
+	public static function factory($ressource = true, $host = '', $dn = '', $passwd = '')
87 87
 	{
88 88
 		$key = md5($host.':'.$dn.':'.$passwd);
89 89
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	static function quote($string)
120 120
 	{
121
-		return str_replace(array('\\','*','(',')','\0',' '),array('\\\\','\*','\(','\)','\\0','\20'),$string);
121
+		return str_replace(array('\\', '*', '(', ')', '\0', ' '), array('\\\\', '\*', '\(', '\)', '\\0', '\20'), $string);
122 122
 	}
123 123
 
124 124
 	/**
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		if (!is_array($ldap)) return false;
133 133
 
134 134
 		$arr = array();
135
-		foreach($ldap as $var => $val)
135
+		foreach ($ldap as $var => $val)
136 136
 		{
137 137
 			if (is_int($var) || $var == 'count') continue;
138 138
 
@@ -164,13 +164,13 @@  discard block
 block discarded – undo
164 164
 	 * @throws Exception\AssertingFailed 'LDAP support unavailable!' (no ldap extension)
165 165
 	 * @throws Exception\NoPermission if bind fails
166 166
 	 */
167
-	function ldapConnect($host='', $dn='', $passwd='')
167
+	function ldapConnect($host = '', $dn = '', $passwd = '')
168 168
 	{
169
-		if(!function_exists('ldap_connect'))
169
+		if (!function_exists('ldap_connect'))
170 170
 		{
171 171
 			if ($this->exception_on_error) throw new Exception\AssertionFailed('LDAP support unavailable!');
172 172
 
173
-			printf('<b>Error: LDAP support unavailable</b><br>',$host);
173
+			printf('<b>Error: LDAP support unavailable</b><br>', $host);
174 174
 			return False;
175 175
 		}
176 176
 		if (empty($host))
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 		{
189 189
 			$host = $_SESSION['ldapConnect'][$host];
190 190
 		}
191
-		foreach($hosts=preg_split('/[ ,;]+/', $host) as $h)
191
+		foreach ($hosts = preg_split('/[ ,;]+/', $host) as $h)
192 192
 		{
193 193
 			if ($this->_connect($h, $dn, $passwd))
194 194
 			{
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 				{
197 197
 					if (isset($_SESSION))	// store working host as first choice in session
198 198
 					{
199
-						$_SESSION['ldapConnect'][$host] = implode(' ',array_unique(array_merge(array($h),$hosts)));
199
+						$_SESSION['ldapConnect'][$host] = implode(' ', array_unique(array_merge(array($h), $hosts)));
200 200
 					}
201 201
 				}
202 202
 				return $this->ds;
@@ -221,20 +221,20 @@  discard block
 block discarded – undo
221 221
 	 */
222 222
 	private function _connect($host, $dn, $passwd)
223 223
 	{
224
-		if (($use_tls = substr($host,0,6) == 'tls://'))
224
+		if (($use_tls = substr($host, 0, 6) == 'tls://'))
225 225
 		{
226
-			$port = parse_url($host,PHP_URL_PORT);
227
-			$host = parse_url($host,PHP_URL_HOST);
226
+			$port = parse_url($host, PHP_URL_PORT);
227
+			$host = parse_url($host, PHP_URL_HOST);
228 228
 		}
229 229
 		// connect to ldap server (never fails, as connection happens in bind!)
230
-		if(!($this->ds = !empty($port) ? ldap_connect($host, $port) : ldap_connect($host)))
230
+		if (!($this->ds = !empty($port) ? ldap_connect($host, $port) : ldap_connect($host)))
231 231
 		{
232 232
 			return False;
233 233
 		}
234 234
 		// set network timeout to not block for minutes
235 235
 		ldap_set_option($this->ds, LDAP_OPT_NETWORK_TIMEOUT, 5);
236 236
 
237
-		if(ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3))
237
+		if (ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3))
238 238
 		{
239 239
 			$supportedLDAPVersion = 3;
240 240
 		}
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 		if ($use_tls) ldap_start_tls($this->ds);
246 246
 
247 247
 		if (!isset($this->ldapserverinfo) ||
248
-			!is_a($this->ldapserverinfo,'EGroupware\Ldap\ServerInfo') ||
248
+			!is_a($this->ldapserverinfo, 'EGroupware\Ldap\ServerInfo') ||
249 249
 			$this->ldapserverinfo->host != $host)
250 250
 		{
251 251
 			//error_log("no ldap server info found");
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 			$this->saveSessionData();
256 256
 		}
257 257
 
258
-		if(!@ldap_bind($this->ds, $dn, $passwd))
258
+		if (!@ldap_bind($this->ds, $dn, $passwd))
259 259
 		{
260 260
 			return False;
261 261
 		}
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	 */
269 269
 	function ldapDisconnect()
270 270
 	{
271
-		if(is_resource($this->ds))
271
+		if (is_resource($this->ds))
272 272
 		{
273 273
 			ldap_unbind($this->ds);
274 274
 			unset($this->ds);
Please login to merge, or discard this patch.
Braces   +36 added lines, -9 removed lines patch added patch discarded remove patch
@@ -129,12 +129,18 @@  discard block
 block discarded – undo
129 129
 	 */
130 130
 	static function result2array($ldap)
131 131
 	{
132
-		if (!is_array($ldap)) return false;
132
+		if (!is_array($ldap))
133
+		{
134
+			return false;
135
+		}
133 136
 
134 137
 		$arr = array();
135 138
 		foreach($ldap as $var => $val)
136 139
 		{
137
-			if (is_int($var) || $var == 'count') continue;
140
+			if (is_int($var) || $var == 'count')
141
+			{
142
+				continue;
143
+			}
138 144
 
139 145
 			if (is_array($val) && $val['count'] == 1)
140 146
 			{
@@ -142,7 +148,10 @@  discard block
 block discarded – undo
142 148
 			}
143 149
 			else
144 150
 			{
145
-				if (is_array($val)) unset($val['count']);
151
+				if (is_array($val))
152
+				{
153
+					unset($val['count']);
154
+				}
146 155
 
147 156
 				$arr[$var] = $val;
148 157
 			}
@@ -168,7 +177,10 @@  discard block
 block discarded – undo
168 177
 	{
169 178
 		if(!function_exists('ldap_connect'))
170 179
 		{
171
-			if ($this->exception_on_error) throw new Exception\AssertionFailed('LDAP support unavailable!');
180
+			if ($this->exception_on_error)
181
+			{
182
+				throw new Exception\AssertionFailed('LDAP support unavailable!');
183
+			}
172 184
 
173 185
 			printf('<b>Error: LDAP support unavailable</b><br>',$host);
174 186
 			return False;
@@ -194,10 +206,13 @@  discard block
 block discarded – undo
194 206
 			{
195 207
 				if ($h !== $host)
196 208
 				{
197
-					if (isset($_SESSION))	// store working host as first choice in session
209
+					if (isset($_SESSION))
210
+					{
211
+						// store working host as first choice in session
198 212
 					{
199 213
 						$_SESSION['ldapConnect'][$host] = implode(' ',array_unique(array_merge(array($h),$hosts)));
200 214
 					}
215
+					}
201 216
 				}
202 217
 				return $this->ds;
203 218
 			}
@@ -206,7 +221,10 @@  discard block
 block discarded – undo
206 221
 				' '.function_backtrace());
207 222
 		}
208 223
 		// give visible error, only if we cant connect to any ldap server
209
-		if ($this->exception_on_error) throw new Exception\NoPermission("Can't connect/bind to LDAP server '$host' and dn='$dn'!");
224
+		if ($this->exception_on_error)
225
+		{
226
+			throw new Exception\NoPermission("Can't connect/bind to LDAP server '$host' and dn='$dn'!");
227
+		}
210 228
 
211 229
 		return false;
212 230
 	}
@@ -242,7 +260,10 @@  discard block
 block discarded – undo
242 260
 		{
243 261
 			$supportedLDAPVersion = 2;
244 262
 		}
245
-		if ($use_tls) ldap_start_tls($this->ds);
263
+		if ($use_tls)
264
+		{
265
+			ldap_start_tls($this->ds);
266
+		}
246 267
 
247 268
 		if (!isset($this->ldapserverinfo) ||
248 269
 			!is_a($this->ldapserverinfo,'EGroupware\Ldap\ServerInfo') ||
@@ -281,10 +302,13 @@  discard block
 block discarded – undo
281 302
 	 */
282 303
 	function restoreSessionData()
283 304
 	{
284
-		if (isset($GLOBALS['egw']->session))	// no availible in setup
305
+		if (isset($GLOBALS['egw']->session))
306
+		{
307
+			// no availible in setup
285 308
 		{
286 309
 			$this->ldapserverinfo = Cache::getSession(__CLASS__, 'ldapServerInfo');
287 310
 		}
311
+		}
288 312
 	}
289 313
 
290 314
 	/**
@@ -292,9 +316,12 @@  discard block
 block discarded – undo
292 316
 	 */
293 317
 	function saveSessionData()
294 318
 	{
295
-		if (isset($GLOBALS['egw']->session))	// no availible in setup
319
+		if (isset($GLOBALS['egw']->session))
320
+		{
321
+			// no availible in setup
296 322
 		{
297 323
 			Cache::setSession(__CLASS__, 'ldapServerInfo', $this->ldapserverinfo);
298 324
 		}
325
+		}
299 326
 	}
300 327
 }
Please login to merge, or discard this patch.
api/src/Ldap/ServerInfo.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	/**
82 82
 	* gets the version
83 83
 	*
84
-	* @return integer the supported ldap version
84
+	* @return string the supported ldap version
85 85
 	*/
86 86
 	function getVersion()
87 87
 	{
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @param resource $ds
160 160
 	 * @param string $host
161 161
 	 * @param int $version 2 or 3
162
-	 * @return ldapserverinfo
162
+	 * @return ServerInfo
163 163
 	 */
164 164
 	public static function get($ds, $host, $version=3)
165 165
 	{
Please login to merge, or discard this patch.
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -32,33 +32,33 @@  discard block
 block discarded – undo
32 32
 	const SAMBA4 = 2;
33 33
 
34 34
 	/**
35
-	* @var array $namingContext holds the supported namingcontexts
36
-	*/
35
+	 * @var array $namingContext holds the supported namingcontexts
36
+	 */
37 37
 	var $namingContext = array();
38 38
 
39 39
 	/**
40
-	* @var string $version holds the LDAP server version
41
-	*/
40
+	 * @var string $version holds the LDAP server version
41
+	 */
42 42
 	var $version = 2;
43 43
 
44 44
 	/**
45
-	* @var integer $serverType holds the type of LDAP server(OpenLDAP, ADS, NDS, ...)
46
-	*/
45
+	 * @var integer $serverType holds the type of LDAP server(OpenLDAP, ADS, NDS, ...)
46
+	 */
47 47
 	var $serverType = 0;
48 48
 
49 49
 	/**
50
-	* @var string $_subSchemaEntry the subschema entry DN
51
-	*/
50
+	 * @var string $_subSchemaEntry the subschema entry DN
51
+	 */
52 52
 	var $subSchemaEntry = '';
53 53
 
54 54
 	/**
55
-	* @var array $supportedObjectClasses the supported objectclasses
56
-	*/
55
+	 * @var array $supportedObjectClasses the supported objectclasses
56
+	 */
57 57
 	var $supportedObjectClasses = array();
58 58
 
59 59
 	/**
60
-	* @var array $supportedOIDs the supported OIDs
61
-	*/
60
+	 * @var array $supportedOIDs the supported OIDs
61
+	 */
62 62
 	var $supportedOIDs = array();
63 63
 
64 64
 	/**
@@ -79,50 +79,50 @@  discard block
 block discarded – undo
79 79
 	}
80 80
 
81 81
 	/**
82
-	* gets the version
83
-	*
84
-	* @return integer the supported ldap version
85
-	*/
82
+	 * gets the version
83
+	 *
84
+	 * @return integer the supported ldap version
85
+	 */
86 86
 	function getVersion()
87 87
 	{
88 88
 		return $this->version;
89 89
 	}
90 90
 
91 91
 	/**
92
-	* sets the namingcontexts
93
-	*
94
-	* @param array $_namingContext the supported namingcontexts
95
-	*/
92
+	 * sets the namingcontexts
93
+	 *
94
+	 * @param array $_namingContext the supported namingcontexts
95
+	 */
96 96
 	function setNamingContexts($_namingContext)
97 97
 	{
98 98
 		$this->namingContext = $_namingContext;
99 99
 	}
100 100
 
101 101
 	/**
102
-	* sets the type of the ldap server(OpenLDAP, ADS, NDS, ...)
103
-	*
104
-	* @param integer $_serverType the type of ldap server
105
-	*/
102
+	 * sets the type of the ldap server(OpenLDAP, ADS, NDS, ...)
103
+	 *
104
+	 * @param integer $_serverType the type of ldap server
105
+	 */
106 106
 	function setServerType($_serverType)
107 107
 	{
108 108
 		$this->serverType = $_serverType;
109 109
 	}
110 110
 
111 111
 	/**
112
-	* sets the DN for the subschema entry
113
-	*
114
-	* @param string $_subSchemaEntry the subschema entry DN
115
-	*/
112
+	 * sets the DN for the subschema entry
113
+	 *
114
+	 * @param string $_subSchemaEntry the subschema entry DN
115
+	 */
116 116
 	function setSubSchemaEntry($_subSchemaEntry)
117 117
 	{
118 118
 		$this->subSchemaEntry = $_subSchemaEntry;
119 119
 	}
120 120
 
121 121
 	/**
122
-	* sets the supported objectclasses
123
-	*
124
-	* @param array $_supportedObjectClasses the supported objectclasses
125
-	*/
122
+	 * sets the supported objectclasses
123
+	 *
124
+	 * @param array $_supportedObjectClasses the supported objectclasses
125
+	 */
126 126
 	function setSupportedObjectClasses($_supportedObjectClasses)
127 127
 	{
128 128
 		$this->supportedOIDs = $_supportedObjectClasses;
@@ -130,20 +130,20 @@  discard block
 block discarded – undo
130 130
 	}
131 131
 
132 132
 	/**
133
-	* sets the version
134
-	*
135
-	* @param integer $_version the supported ldap version
136
-	*/
133
+	 * sets the version
134
+	 *
135
+	 * @param integer $_version the supported ldap version
136
+	 */
137 137
 	function setVersion($_version)
138 138
 	{
139 139
 		$this->version = $_version;
140 140
 	}
141 141
 
142 142
 	/**
143
-	* checks for supported objectclasses
144
-	*
145
-	* @return bool returns true if the ldap server supports this objectclass
146
-	*/
143
+	 * checks for supported objectclasses
144
+	 *
145
+	 * @return bool returns true if the ldap server supports this objectclass
146
+	 */
147 147
 	function supportsObjectClass($_objectClass)
148 148
 	{
149 149
 		if($this->supportedObjectClasses[strtolower($_objectClass)])
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	*/
147 147
 	function supportsObjectClass($_objectClass)
148 148
 	{
149
-		if($this->supportedObjectClasses[strtolower($_objectClass)])
149
+		if ($this->supportedObjectClasses[strtolower($_objectClass)])
150 150
 		{
151 151
 			return true;
152 152
 		}
@@ -161,21 +161,21 @@  discard block
 block discarded – undo
161 161
 	 * @param int $version 2 or 3
162 162
 	 * @return ldapserverinfo
163 163
 	 */
164
-	public static function get($ds, $host, $version=3)
164
+	public static function get($ds, $host, $version = 3)
165 165
 	{
166
-		$filter='(objectclass=*)';
167
-		$justthese = array('structuralObjectClass','namingContexts','supportedLDAPVersion','subschemaSubentry','vendorname');
168
-		if(($sr = @ldap_read($ds, '', $filter, $justthese)))
166
+		$filter = '(objectclass=*)';
167
+		$justthese = array('structuralObjectClass', 'namingContexts', 'supportedLDAPVersion', 'subschemaSubentry', 'vendorname');
168
+		if (($sr = @ldap_read($ds, '', $filter, $justthese)))
169 169
 		{
170
-			if(($info = ldap_get_entries($ds, $sr)))
170
+			if (($info = ldap_get_entries($ds, $sr)))
171 171
 			{
172 172
 				$ldapServerInfo = new ServerInfo($host);
173 173
 				$ldapServerInfo->setVersion($version);
174 174
 
175 175
 				// check for naming contexts
176
-				if($info[0]['namingcontexts'])
176
+				if ($info[0]['namingcontexts'])
177 177
 				{
178
-					for($i=0; $i<$info[0]['namingcontexts']['count']; $i++)
178
+					for ($i = 0; $i < $info[0]['namingcontexts']['count']; $i++)
179 179
 					{
180 180
 						$namingcontexts[] = $info[0]['namingcontexts'][$i];
181 181
 					}
@@ -183,9 +183,9 @@  discard block
 block discarded – undo
183 183
 				}
184 184
 
185 185
 				// check for ldap server type
186
-				if($info[0]['structuralobjectclass'])
186
+				if ($info[0]['structuralobjectclass'])
187 187
 				{
188
-					switch($info[0]['structuralobjectclass'][0])
188
+					switch ($info[0]['structuralobjectclass'][0])
189 189
 					{
190 190
 						case 'OpenLDAProotDSE':
191 191
 							$ldapServerType = OPENLDAP_LDAPSERVER;
@@ -202,30 +202,30 @@  discard block
 block discarded – undo
202 202
 				}
203 203
 
204 204
 				// check for subschema entry dn
205
-				if($info[0]['subschemasubentry'])
205
+				if ($info[0]['subschemasubentry'])
206 206
 				{
207 207
 					$subschemasubentry = $info[0]['subschemasubentry'][0];
208 208
 					$ldapServerInfo->setSubSchemaEntry($subschemasubentry);
209 209
 				}
210 210
 
211 211
 				// create list of supported objetclasses
212
-				if(!empty($subschemasubentry))
212
+				if (!empty($subschemasubentry))
213 213
 				{
214
-					$filter='(objectclass=*)';
214
+					$filter = '(objectclass=*)';
215 215
 					$justthese = array('objectClasses');
216 216
 
217
-					if(($sr = ldap_read($ds, $subschemasubentry, $filter, $justthese)))
217
+					if (($sr = ldap_read($ds, $subschemasubentry, $filter, $justthese)))
218 218
 					{
219
-						if(($info = ldap_get_entries($ds, $sr)))
219
+						if (($info = ldap_get_entries($ds, $sr)))
220 220
 						{
221
-							if($info[0]['objectclasses']) {
222
-								for($i=0; $i<$info[0]['objectclasses']['count']; $i++)
221
+							if ($info[0]['objectclasses']) {
222
+								for ($i = 0; $i < $info[0]['objectclasses']['count']; $i++)
223 223
 								{
224 224
 									$matches = null;
225
-									if(preg_match('/^\( (.*) NAME \'(\w*)\' /', $info[0]['objectclasses'][$i], $matches))
225
+									if (preg_match('/^\( (.*) NAME \'(\w*)\' /', $info[0]['objectclasses'][$i], $matches))
226 226
 									{
227 227
 										#_debug_array($matches);
228
-										if(count($matches) == 3)
228
+										if (count($matches) == 3)
229 229
 										{
230 230
 											$supportedObjectClasses[$matches[1]] = strtolower($matches[2]);
231 231
 										}
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -218,7 +218,8 @@
 block discarded – undo
218 218
 					{
219 219
 						if(($info = ldap_get_entries($ds, $sr)))
220 220
 						{
221
-							if($info[0]['objectclasses']) {
221
+							if($info[0]['objectclasses'])
222
+							{
222 223
 								for($i=0; $i<$info[0]['objectclasses']['count']; $i++)
223 224
 								{
224 225
 									$matches = null;
Please login to merge, or discard this patch.
api/src/Link.php 4 patches
Doc Comments   +3 added lines, -5 removed lines patch added patch discarded remove patch
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	 * generate temporary link_id used as array-key
434 434
 	 *
435 435
 	 * @param string $app app-name
436
-	 * @param mixed $id
436
+	 * @param string $id
437 437
 	 * @return string
438 438
 	 */
439 439
 	static function temp_link_id($app,$id)
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 	 * @param string|array $id ='' id if $app_link_id is an appname or array with links, if 1. entry not yet created
580 580
 	 * @param string $app2 ='' second app
581 581
 	 * @param string $id2 ='' id in $app2
582
-	 * @return array with link-data or False
582
+	 * @return string with link-data or False
583 583
 	 */
584 584
 	static function get_link($app_link_id,$id='',$app2='',$id2='')
585 585
 	{
@@ -734,7 +734,6 @@  discard block
 block discarded – undo
734 734
 	 *
735 735
 	 * @param string $app app to search
736 736
 	 * @param string $pattern pattern to search
737
-	 * @param string $type Search only a certain sub-type of records (optional)
738 737
 	 * @return array with $id => $title pairs of matching entries of app
739 738
 	 */
740 739
 	static function query($app,$pattern, &$options = array())
@@ -1232,7 +1231,6 @@  discard block
 block discarded – undo
1232 1231
 	 * @param string $app appname to link the file to
1233 1232
 	 * @param string $id id in $app
1234 1233
 	 * @param string $file VFS path to link to
1235
-	 * @param string $comment ='' comment to add to the link
1236 1234
 	 */
1237 1235
 	static function link_file($app,$id,$file)//,$comment='')
1238 1236
 	{
@@ -1259,7 +1257,7 @@  discard block
 block discarded – undo
1259 1257
 	 * @param int|string $app > 0: file_id of an attchemnt or $app/$id entry which linked to
1260 1258
 	 * @param string $id ='' id in app
1261 1259
 	 * @param string $fname ='' filename
1262
-	 * @return boolean|array false on error ($app or $id not found), array with path as key and boolean result of delete
1260
+	 * @return boolean false on error ($app or $id not found), array with path as key and boolean result of delete
1263 1261
 	 */
1264 1262
 	static function delete_attached($app,$id='',$fname='')
1265 1263
 	{
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 		}
481 481
 		$ids = Link\Storage::get_links($app, $id, $only_app, $order, $deleted, $limit);
482 482
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
483
-		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
483
+			($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
484 484
 		{
485 485
 			if (($vfs_ids = self::list_attached($app,$id)))
486 486
 			{
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 		$links = Link\Storage::get_links($app,$ids,$only_app,$order,$deleted);
537 537
 
538 538
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
539
-		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
539
+			($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
540 540
 		{
541 541
 			// todo do that in a single query, eg. directory listing, too
542 542
 			foreach($ids as $id)
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
 
794 794
 		if (!isset($options['total']))
795 795
 		{
796
-		       $options['total'] = count($result);
796
+			   $options['total'] = count($result);
797 797
 		}
798 798
 		if (is_array($result) && (isset($options['start']) || (isset($options['num_rows']) && count($result) > $options['num_rows'])))
799 799
 		{
Please login to merge, or discard this patch.
Spacing   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	/**
114 114
 	 * appname used for returned attached files (!= 'filemanager'!)
115 115
 	 */
116
-	const VFS_APPNAME = 'file';		// pseudo-appname for own file-attachments in vfs, this is NOT the vfs-app
116
+	const VFS_APPNAME = 'file'; // pseudo-appname for own file-attachments in vfs, this is NOT the vfs-app
117 117
 
118 118
 	/**
119 119
 	 * Appname used of files stored via Link::set_data()
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 			'icon' => 'addressbook/accounts',
147 147
 			'query' => 'accounts::link_query',
148 148
 			'title' => 'EGroupware\\Api\\Accounts::username',
149
-			'view' => array('menuaction'=>'addressbook.addressbook_ui.view','ajax'=>'true'),
149
+			'view' => array('menuaction'=>'addressbook.addressbook_ui.view', 'ajax'=>'true'),
150 150
 			'view_id' => 'account_id'
151 151
 		),
152 152
 		'api' => array(
@@ -207,19 +207,19 @@  discard block
 block discarded – undo
207 207
 		// for performance reasons, we do it only once / cache it in the session
208 208
 		if (!($search_link_hooks = Cache::getSession(__CLASS__, 'search_link_hooks')))
209 209
 		{
210
-			$search_link_hooks = Hooks::process('search_link',array(), (bool)$GLOBALS['egw_info']['flags']['async-service']);
210
+			$search_link_hooks = Hooks::process('search_link', array(), (bool)$GLOBALS['egw_info']['flags']['async-service']);
211 211
 			Cache::setSession(__CLASS__, 'search_link_hooks', $search_link_hooks);
212 212
 		}
213 213
 		if (is_array($search_link_hooks))
214 214
 		{
215
-			foreach($search_link_hooks as $app => $data)
215
+			foreach ($search_link_hooks as $app => $data)
216 216
 			{
217 217
 				// allow apps to register additional types
218 218
 				if (isset($data['additional']))
219 219
 				{
220
-					foreach($data['additional'] as $name => $values)
220
+					foreach ($data['additional'] as $name => $values)
221 221
 					{
222
-						$values['app'] = $app;	// store name of registring app, to be able to check access
222
+						$values['app'] = $app; // store name of registring app, to be able to check access
223 223
 						self::$app_register[$name] = $values;
224 224
 					}
225 225
 					unset($data['additional']);
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 				{
230 230
 					$data['list'] = array('menuaction' => $data['view_list']);
231 231
 				}
232
-				elseif(isset($data['list']) && !isset($data['view_list']))
232
+				elseif (isset($data['list']) && !isset($data['view_list']))
233 233
 				{
234 234
 					$data['view_list'] = $data['list']['menuaction'];
235 235
 				}
@@ -273,18 +273,18 @@  discard block
 block discarded – undo
273 273
 	public static function json_registry()
274 274
 	{
275 275
 		$to_json = array();
276
-		foreach(self::$app_register as $app => $data)
276
+		foreach (self::$app_register as $app => $data)
277 277
 		{
278 278
 			if (isset($GLOBALS['egw_info']['user']['apps'][$app]) ||
279 279
 				isset($data['app']) && isset($GLOBALS['egw_info']['user']['apps'][$data['app']]))
280 280
 			{
281 281
 				$to_json[$app] = array_intersect_key($data, array_flip(array(
282
-					'view','view_id','view_popup',
283
-					'add','add_app','add_id','add_popup',
284
-					'edit','edit_id','edit_popup',
285
-					'list','list_popup',
286
-					'name','icon','query',
287
-					'mime','entry','entries',
282
+					'view', 'view_id', 'view_popup',
283
+					'add', 'add_app', 'add_id', 'add_popup',
284
+					'edit', 'edit_id', 'edit_popup',
285
+					'list', 'list_popup',
286
+					'name', 'icon', 'query',
287
+					'mime', 'entry', 'entries',
288 288
 				)));
289 289
 			}
290 290
 		}
@@ -329,11 +329,11 @@  discard block
 block discarded – undo
329 329
 	 * @param int $no_notify =0 &1 dont notify $app1, &2 dont notify $app2
330 330
 	 * @return int/boolean False (for db or param-error) or on success link_id (Please not the return-value of $id1)
331 331
 	 */
332
-	static function link( $app1,&$id1,$app2,$id2='',$remark='',$owner=0,$lastmod=0,$no_notify=0 )
332
+	static function link($app1, &$id1, $app2, $id2 = '', $remark = '', $owner = 0, $lastmod = 0, $no_notify = 0)
333 333
 	{
334 334
 		if (self::DEBUG)
335 335
 		{
336
-			echo "<p>Link::link('$app1',$id1,'".print_r($app2,true)."',".print_r($id2,true).",'$remark',$owner,$lastmod)</p>\n";
336
+			echo "<p>Link::link('$app1',$id1,'".print_r($app2, true)."',".print_r($id2, true).",'$remark',$owner,$lastmod)</p>\n";
337 337
 		}
338 338
 		if (!$app1 || !$app2 || $app1 == $app2 && $id1 == $id2)
339 339
 		{
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 				}
353 353
 				if (is_array($id1) || !$id1)		// create link only in $id1 array
354 354
 				{
355
-					self::link($app1, $id1, $link['app'], $link['id'], $link['remark'],$link['owner'],$link['lastmod']);
355
+					self::link($app1, $id1, $link['app'], $link['id'], $link['remark'], $link['owner'], $link['lastmod']);
356 356
 					continue;
357 357
 				}
358 358
 				switch ($link['app'])
@@ -365,19 +365,19 @@  discard block
 block discarded – undo
365 365
 						}
366 366
 						// fall through
367 367
 					case self::VFS_APPNAME:
368
-						$link_id = self::attach_file($app1,$id1,$link['id'],$link['remark']);
368
+						$link_id = self::attach_file($app1, $id1, $link['id'], $link['remark']);
369 369
 						break;
370 370
 
371 371
 					case self::VFS_LINK:
372
-						$link_id = self::link_file($app1,$id1, $link['id'],$link['remark']);
372
+						$link_id = self::link_file($app1, $id1, $link['id'], $link['remark']);
373 373
 						break;
374 374
 
375 375
 					default:
376
-						$link_id = Link\Storage::link($app1,$id1,$link['app'],$link['id'],
377
-							$link['remark'],$link['owner'],$link['lastmod']);
376
+						$link_id = Link\Storage::link($app1, $id1, $link['app'], $link['id'],
377
+							$link['remark'], $link['owner'], $link['lastmod']);
378 378
 						// notify both sides
379
-						if (!($no_notify&2)) self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id);
380
-						if (!($no_notify&1)) self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id);
379
+						if (!($no_notify&2)) self::notify('link', $link['app'], $link['id'], $app1, $id1, $link_id);
380
+						if (!($no_notify&1)) self::notify('link', $app1, $id1, $link['app'], $link['id'], $link_id);
381 381
 						break;
382 382
 				}
383 383
 			}
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 			{
390 390
 				$id1 = array( );
391 391
 			}
392
-			$link_id = self::temp_link_id($app2,$id2);
392
+			$link_id = self::temp_link_id($app2, $id2);
393 393
 
394 394
 			$id1[$link_id] = array(
395 395
 				'app' => $app2,
@@ -407,24 +407,24 @@  discard block
 block discarded – undo
407 407
 		}
408 408
 		if ($app1 == self::VFS_LINK)
409 409
 		{
410
-			return self::link_file($app2,$id2,$id1,$remark);
410
+			return self::link_file($app2, $id2, $id1, $remark);
411 411
 		}
412 412
 		elseif ($app2 == self::VFS_LINK)
413 413
 		{
414
-			return self::link_file($app1,$id1,$id2,$remark);
414
+			return self::link_file($app1, $id1, $id2, $remark);
415 415
 		}
416 416
 		if ($app1 == self::VFS_APPNAME)
417 417
 		{
418
-			return self::attach_file($app2,$id2,$id1,$remark);
418
+			return self::attach_file($app2, $id2, $id1, $remark);
419 419
 		}
420 420
 		elseif ($app2 == self::VFS_APPNAME)
421 421
 		{
422
-			return self::attach_file($app1,$id1,$id2,$remark);
422
+			return self::attach_file($app1, $id1, $id2, $remark);
423 423
 		}
424
-		$link_id = Link\Storage::link($app1,$id1,$app2,$id2,$remark,$owner);
424
+		$link_id = Link\Storage::link($app1, $id1, $app2, $id2, $remark, $owner);
425 425
 
426
-		if (!($no_notify&2)) self::notify('link',$app2,$id2,$app1,$id1,$link_id);
427
-		if (!($no_notify&1)) self::notify('link',$app1,$id1,$app2,$id2,$link_id);
426
+		if (!($no_notify&2)) self::notify('link', $app2, $id2, $app1, $id1, $link_id);
427
+		if (!($no_notify&1)) self::notify('link', $app1, $id1, $app2, $id2, $link_id);
428 428
 
429 429
 		return $link_id;
430 430
 	}
@@ -436,9 +436,9 @@  discard block
 block discarded – undo
436 436
 	 * @param mixed $id
437 437
 	 * @return string
438 438
 	 */
439
-	static function temp_link_id($app,$id)
439
+	static function temp_link_id($app, $id)
440 440
 	{
441
-		return $app.':'.(!in_array($app, array(self::VFS_APPNAME,self::VFS_LINK, self::DATA_APPNAME)) ? $id : $id['name']);
441
+		return $app.':'.(!in_array($app, array(self::VFS_APPNAME, self::VFS_LINK, self::DATA_APPNAME)) ? $id : $id['name']);
442 442
 	}
443 443
 
444 444
 	/**
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 	 * @param int $limit =null number of entries to return, only affects links, attachments are allways reported!
455 455
 	 * @return array id => links pairs if $id is an array or just the links (only_app: ids) or empty array if no matching links found
456 456
 	 */
457
-	static function get_links($app, $id, $only_app='', $order='link_lastmod DESC',$cache_titles=false, $deleted=false, $limit=null)
457
+	static function get_links($app, $id, $only_app = '', $order = 'link_lastmod DESC', $cache_titles = false, $deleted = false, $limit = null)
458 458
 	{
459 459
 		if (self::DEBUG) echo "<p>Link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n";
460 460
 
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 			{
466 466
 				if (($not_only = $only_app[0] == '!'))
467 467
 				{
468
-					$only_app = substr(1,$only_app);
468
+					$only_app = substr(1, $only_app);
469 469
 				}
470 470
 				foreach (array_reverse($id) as $link)
471 471
 				{
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
483 483
 		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
484 484
 		{
485
-			if (($vfs_ids = self::list_attached($app,$id)))
485
+			if (($vfs_ids = self::list_attached($app, $id)))
486 486
 			{
487 487
 				$ids += $vfs_ids;
488 488
 			}
@@ -492,18 +492,18 @@  discard block
 block discarded – undo
492 492
 		{
493 493
 			// agregate links by app
494 494
 			$app_ids = array();
495
-			foreach($ids as $link)
495
+			foreach ($ids as $link)
496 496
 			{
497 497
 				$app_ids[$link['app']][] = $link['id'];
498 498
 			}
499
-			foreach($app_ids as $appname => $a_ids)
499
+			foreach ($app_ids as $appname => $a_ids)
500 500
 			{
501
-				self::titles($appname,array_unique($a_ids));
501
+				self::titles($appname, array_unique($a_ids));
502 502
 			}
503 503
 			// remove links, current user has no access, from result
504
-			foreach($ids as $key => $link)
504
+			foreach ($ids as $key => $link)
505 505
 			{
506
-				if (!self::title($link['app'],$link['id']))
506
+				if (!self::title($link['app'], $link['id']))
507 507
 				{
508 508
 					unset($ids[$key]);
509 509
 				}
@@ -525,27 +525,27 @@  discard block
 block discarded – undo
525 525
 	 * @param boolean $deleted =false Include links that have been flagged as deleted, waiting for purge of linked record.
526 526
 	 * @return array of $id => array($links) pairs
527 527
 	 */
528
-	static function get_links_multiple($app,array $ids,$cache_titles=true,$only_app='',$order='link_lastmod DESC', $deleted=false )
528
+	static function get_links_multiple($app, array $ids, $cache_titles = true, $only_app = '', $order = 'link_lastmod DESC', $deleted = false)
529 529
 	{
530
-		if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n";
530
+		if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids, true).",$cache_titles,'$only_app','$order')</p>\n";
531 531
 
532 532
 		if (!$ids)
533 533
 		{
534
-			return array();		// no ids are linked to nothing
534
+			return array(); // no ids are linked to nothing
535 535
 		}
536
-		$links = Link\Storage::get_links($app,$ids,$only_app,$order,$deleted);
536
+		$links = Link\Storage::get_links($app, $ids, $only_app, $order, $deleted);
537 537
 
538 538
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
539 539
 		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
540 540
 		{
541 541
 			// todo do that in a single query, eg. directory listing, too
542
-			foreach($ids as $id)
542
+			foreach ($ids as $id)
543 543
 			{
544 544
 				if (!isset($links[$id]))
545 545
 				{
546 546
 					$links[$id] = array();
547 547
 				}
548
-				if (($vfs_ids = self::list_attached($app,$id)))
548
+				if (($vfs_ids = self::list_attached($app, $id)))
549 549
 				{
550 550
 					$links[$id] += $vfs_ids;
551 551
 				}
@@ -555,16 +555,16 @@  discard block
 block discarded – undo
555 555
 		{
556 556
 			// agregate links by app
557 557
 			$app_ids = array();
558
-			foreach($links as &$targets)
558
+			foreach ($links as &$targets)
559 559
 			{
560
-				foreach($targets as $link)
560
+				foreach ($targets as $link)
561 561
 				{
562 562
 					if (is_array($link)) $app_ids[$link['app']][] = $link['id'];
563 563
 				}
564 564
 			}
565
-			foreach($app_ids as $app => $a_ids)
565
+			foreach ($app_ids as $app => $a_ids)
566 566
 			{
567
-				self::titles($app,array_unique($a_ids));
567
+				self::titles($app, array_unique($a_ids));
568 568
 			}
569 569
 		}
570 570
 		return $links;
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 	 * @param string $id2 ='' id in $app2
582 582
 	 * @return array with link-data or False
583 583
 	 */
584
-	static function get_link($app_link_id,$id='',$app2='',$id2='')
584
+	static function get_link($app_link_id, $id = '', $app2 = '', $id2 = '')
585 585
 	{
586 586
 		if (self::DEBUG)
587 587
 		{
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 		}
590 590
 		if (is_array($id))
591 591
 		{
592
-			if (strpos($app_link_id,':') === false) $app_link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
592
+			if (strpos($app_link_id, ':') === false) $app_link_id = self::temp_link_id($app2, $id2); // create link_id of temporary link, if not given
593 593
 
594 594
 			if (isset($id[$app_link_id]) && is_array($id[$app_link_id]))	// check for unlinked-marker
595 595
 			{
@@ -605,11 +605,11 @@  discard block
 block discarded – undo
605 605
 			}
606 606
 			if ($app_link_id == self::VFS_APPNAME)
607 607
 			{
608
-				return self::info_attached($app2,$id2,$id);
608
+				return self::info_attached($app2, $id2, $id);
609 609
 			}
610
-			return self::info_attached($app_link_id,$id,$id2);
610
+			return self::info_attached($app_link_id, $id, $id2);
611 611
 		}
612
-		return Link\Storage::get_link($app_link_id,$id,$app2,$id2);
612
+		return Link\Storage::get_link($app_link_id, $id, $app2, $id2);
613 613
 	}
614 614
 
615 615
 	/**
@@ -627,9 +627,9 @@  discard block
 block discarded – undo
627 627
 	 * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete
628 628
 	 * @return the number of links deleted
629 629
 	 */
630
-	static function unlink($link_id,$app='',$id='',$owner=0,$app2='',$id2='',$hold_for_purge=false)
630
+	static function unlink($link_id, $app = '', $id = '', $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false)
631 631
 	{
632
-		return self::unlink2($link_id,$app,$id,$owner,$app2,$id2,$hold_for_purge);
632
+		return self::unlink2($link_id, $app, $id, $owner, $app2, $id2, $hold_for_purge);
633 633
 	}
634 634
 
635 635
 	/**
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 	 * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete
645 645
 	 * @return the number of links deleted
646 646
 	 */
647
-	static function unlink2($link_id,$app,&$id,$owner=0,$app2='',$id2='',$hold_for_purge=false)
647
+	static function unlink2($link_id, $app, &$id, $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false)
648 648
 	{
649 649
 		if (self::DEBUG)
650 650
 		{
@@ -656,22 +656,22 @@  discard block
 block discarded – undo
656 656
 		}
657 657
 		elseif ($app == self::VFS_APPNAME)
658 658
 		{
659
-			return self::delete_attached($app2,$id2,$id);
659
+			return self::delete_attached($app2, $id2, $id);
660 660
 		}
661 661
 		elseif ($app2 == self::VFS_APPNAME)
662 662
 		{
663
-			return self::delete_attached($app,$id,$id2);
663
+			return self::delete_attached($app, $id, $id2);
664 664
 		}
665 665
 		if (!is_array($id))
666 666
 		{
667 667
 			if (!$link_id && !$app2 && !$id2 && $app2 != '!'.self::VFS_APPNAME)
668 668
 			{
669
-				self::delete_attached($app,$id);	// deleting all attachments
670
-				self::delete_cache($app,$id);
669
+				self::delete_attached($app, $id); // deleting all attachments
670
+				self::delete_cache($app, $id);
671 671
 			}
672 672
 
673 673
 			// Log in history
674
-			if($link_id && (!$app || !$app2))
674
+			if ($link_id && (!$app || !$app2))
675 675
 			{
676 676
 				// Need to load it first
677 677
 				$link = self::get_link($link_id);
@@ -682,21 +682,21 @@  discard block
 block discarded – undo
682 682
 			}
683 683
 			if ($app && $app2)
684 684
 			{
685
-				Storage\History::static_add($app,$id,$GLOBALS['egw_info']['user']['account_id'],'~link~','',$app2.':'.$id2);
686
-				Storage\History::static_add($app2,$id2,$GLOBALS['egw_info']['user']['account_id'],'~link~','',$app.':'.$id);
685
+				Storage\History::static_add($app, $id, $GLOBALS['egw_info']['user']['account_id'], '~link~', '', $app2.':'.$id2);
686
+				Storage\History::static_add($app2, $id2, $GLOBALS['egw_info']['user']['account_id'], '~link~', '', $app.':'.$id);
687 687
 			}
688
-			$deleted =& Link\Storage::unlink($link_id,$app,$id,$owner,$app2 != '!'.self::VFS_APPNAME ? $app2 : '',$id2,$hold_for_purge);
688
+			$deleted = & Link\Storage::unlink($link_id, $app, $id, $owner, $app2 != '!'.self::VFS_APPNAME ? $app2 : '', $id2, $hold_for_purge);
689 689
 
690 690
 			// only notify on real links, not the one cached for writing or fileattachments
691 691
 			self::notify_unlink($deleted);
692 692
 
693 693
 			return count($deleted);
694 694
 		}
695
-		if (!$link_id) $link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
695
+		if (!$link_id) $link_id = self::temp_link_id($app2, $id2); // create link_id of temporary link, if not given
696 696
 
697 697
 		if (isset($id[$link_id]))
698 698
 		{
699
-			$id[$link_id] = False;	// set the unlink marker
699
+			$id[$link_id] = False; // set the unlink marker
700 700
 
701 701
 			if (self::DEBUG)
702 702
 			{
@@ -713,10 +713,10 @@  discard block
 block discarded – undo
713 713
 	 * @param string $must_support capability the apps need to support, eg. 'add', default ''=list all apps
714 714
 	 * @return array with app => title pairs
715 715
 	 */
716
-	static function app_list($must_support='')
716
+	static function app_list($must_support = '')
717 717
 	{
718 718
 		$apps = array();
719
-		foreach(self::$app_register as $type => $reg)
719
+		foreach (self::$app_register as $type => $reg)
720 720
 		{
721 721
 			if ($must_support && !isset($reg[$must_support])) continue;
722 722
 
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
 	 * @param string $type Search only a certain sub-type of records (optional)
738 738
 	 * @return array with $id => $title pairs of matching entries of app
739 739
 	 */
740
-	static function query($app,$pattern, &$options = array())
740
+	static function query($app, $pattern, &$options = array())
741 741
 	{
742 742
 		if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['query']))
743 743
 		{
@@ -753,14 +753,14 @@  discard block
 block discarded – undo
753 753
 
754 754
 		// See etemplate's nextmatch widget, following was copied from there
755 755
 		// allow static callbacks
756
-		if(strpos($method,'::') !== false)
756
+		if (strpos($method, '::') !== false)
757 757
 		{
758 758
 			//  workaround for php < 5.3: do NOT call it static, but allow application code to specify static callbacks
759
-			if (version_compare(PHP_VERSION,'5.3','<')) list($class,$method) = explode('::',$method);
759
+			if (version_compare(PHP_VERSION, '5.3', '<')) list($class, $method) = explode('::', $method);
760 760
 		}
761 761
 		else
762 762
 		{
763
-			list($app,$class,$method) = explode('.',$method);
763
+			list($app, $class, $method) = explode('.', $method);
764 764
 		}
765 765
 		if ($class)
766 766
 		{
@@ -777,13 +777,13 @@  discard block
 block discarded – undo
777 777
 				$obj = CreateObject($app.'.'.$class);
778 778
 			}
779 779
 		}
780
-		if(is_callable($method))        // php5.3+ call
780
+		if (is_callable($method))        // php5.3+ call
781 781
 		{
782
-			$result = call_user_func($method,$pattern,$options);
782
+			$result = call_user_func($method, $pattern, $options);
783 783
 		}
784
-		elseif(is_object($obj) && method_exists($obj,$method))
784
+		elseif (is_object($obj) && method_exists($obj, $method))
785 785
 		{
786
-			$result = $obj->$method($pattern,$options);
786
+			$result = $obj->$method($pattern, $options);
787 787
 		}
788 788
 		else
789 789
 		{
@@ -811,11 +811,11 @@  discard block
 block discarded – undo
811 811
 	 * @param array $link =null link-data for file-attachments
812 812
 	 * @return string/boolean string with title, null if $id does not exist in $app or false if no perms to view it
813 813
 	 */
814
-	static function title($app,$id,$link=null)
814
+	static function title($app, $id, $link = null)
815 815
 	{
816 816
 		if (!$id) return '';
817 817
 
818
-		$title =& self::get_cache($app,$id);
818
+		$title = & self::get_cache($app, $id);
819 819
 		if (isset($title) && !empty($title) && !is_array($id))
820 820
 		{
821 821
 			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n";
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 		}
849 849
 		$method = $reg['title'];
850 850
 
851
-		if (true) $title = ExecMethod($method,$id);
851
+		if (true) $title = ExecMethod($method, $id);
852 852
 
853 853
 		if ($id && is_null($title))	// $app,$id has been deleted ==> unlink all links to it
854 854
 		{
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 			if (!isset($unlinking[$app]) || !isset($unlinking[$app][$id]))
858 858
 			{
859 859
 				$unlinking[$app][$id] = true;
860
-				self::unlink(0,$app,$id);
860
+				self::unlink(0, $app, $id);
861 861
 				unset($unlinking[$app][$id]);
862 862
 			}
863 863
 			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n";
@@ -882,36 +882,36 @@  discard block
 block discarded – undo
882 882
 	 * @param string $app
883 883
 	 * @param array $ids
884 884
 	 */
885
-	static function titles($app,array $ids)
885
+	static function titles($app, array $ids)
886 886
 	{
887 887
 		if (self::DEBUG)
888 888
 		{
889
-			echo "<p>".__METHOD__."($app,".implode(',',$ids).")</p>\n";
889
+			echo "<p>".__METHOD__."($app,".implode(',', $ids).")</p>\n";
890 890
 		}
891 891
 		$titles = $ids_to_query = array();
892
-		foreach($ids as $id)
892
+		foreach ($ids as $id)
893 893
 		{
894
-			$title =& self::get_cache($app,$id);
894
+			$title = & self::get_cache($app, $id);
895 895
 			if (!isset($title))
896 896
 			{
897 897
 				if (isset(self::$app_register[$app]['titles']))
898 898
 				{
899
-					$ids_to_query[] = $id;	// titles method --> collect links to query at once
899
+					$ids_to_query[] = $id; // titles method --> collect links to query at once
900 900
 				}
901 901
 				else
902 902
 				{
903
-					$title = self::title($app,$id);	// no titles method --> fallback to query each link separate
903
+					$title = self::title($app, $id); // no titles method --> fallback to query each link separate
904 904
 				}
905 905
 			}
906 906
 			$titles[$id] = $title;
907 907
 		}
908 908
 		if ($ids_to_query)
909 909
 		{
910
-			for ($n = 0; ($ids = array_slice($ids_to_query,$n*self::MAX_TITLES_QUERY,self::MAX_TITLES_QUERY)); ++$n)
910
+			for ($n = 0; ($ids = array_slice($ids_to_query, $n * self::MAX_TITLES_QUERY, self::MAX_TITLES_QUERY)); ++$n)
911 911
 			{
912
-				foreach(ExecMethod(self::$app_register[$app]['titles'],$ids) as $id => $t)
912
+				foreach (ExecMethod(self::$app_register[$app]['titles'], $ids) as $id => $t)
913 913
 				{
914
-					$title =& self::get_cache($app,$id);
914
+					$title = & self::get_cache($app, $id);
915 915
 					$titles[$id] = $title = $t;
916 916
 				}
917 917
 			}
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
 	 * @param string $to_id =''id in $to_app
928 928
 	 * @return array/boolean with name-value pairs for link to add-methode of $app or false if add not supported
929 929
 	 */
930
-	static function add($app,$to_app='',$to_id='')
930
+	static function add($app, $to_app = '', $to_id = '')
931 931
 	{
932 932
 		//echo "<p>Link::add('$app','$to_app','$to_id') app_register[$app] ="; _debug_array($app_register[$app]);
933 933
 		if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['add']))
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
 	 * @param string &$popup=null on return popup size eg. '600x400' or null
953 953
 	 * @return array|boolean with name-value pairs for link to edit-methode of $app or false if edit not supported
954 954
 	 */
955
-	static function edit($app,$id,&$popup=null)
955
+	static function edit($app, $id, &$popup = null)
956 956
 	{
957 957
 		//echo "<p>Link::add('$app','$to_app','$to_id') app_register[$app] ="; _debug_array($app_register[$app]);
958 958
 		if (empty($app) || empty($id) || !is_array($reg = self::$app_register[$app]) || !isset($reg['edit']))
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
 			if ($reg && isset($reg['view']))
961 961
 			{
962 962
 				$popup = $reg['view_popup'];
963
-				return self::view($app,$id);	// fallback to view
963
+				return self::view($app, $id); // fallback to view
964 964
 			}
965 965
 			return false;
966 966
 		}
@@ -980,12 +980,12 @@  discard block
 block discarded – undo
980 980
 	 * @param array $link =null link-data for file-attachments
981 981
 	 * @return array with name-value pairs for link to view-methode of $app to view $id
982 982
 	 */
983
-	static function view($app,$id,$link=null)
983
+	static function view($app, $id, $link = null)
984 984
 	{
985 985
 		if ($app == self::VFS_APPNAME && !empty($id) && is_array($link))
986 986
 		{
987 987
 			//return Vfs::download_url(self::vfs_path($link['app2'],$link['id2'],$link['id'],true));
988
-			return self::mime_open(self::vfs_path($link['app2'],$link['id2'],$link['id'],true), $link['type']);
988
+			return self::mime_open(self::vfs_path($link['app2'], $link['id2'], $link['id'], true), $link['type']);
989 989
 		}
990 990
 		if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['view']) || !isset($reg['view_id']))
991 991
 		{
@@ -993,11 +993,11 @@  discard block
 block discarded – undo
993 993
 		}
994 994
 		$view = $reg['view'];
995 995
 
996
-		$names = explode(':',$reg['view_id']);
996
+		$names = explode(':', $reg['view_id']);
997 997
 		if (count($names) > 1)
998 998
 		{
999
-			$id = explode(':',$id);
1000
-			while (list($n,$name) = each($names))
999
+			$id = explode(':', $id);
1000
+			while (list($n, $name) = each($names))
1001 1001
 			{
1002 1002
 				$view[$name] = $id[$n];
1003 1003
 			}
@@ -1021,13 +1021,13 @@  discard block
 block discarded – undo
1021 1021
 	 */
1022 1022
 	static function get_mime_info($type)
1023 1023
 	{
1024
-		foreach(self::$app_register as $app => $registry)
1024
+		foreach (self::$app_register as $app => $registry)
1025 1025
 		{
1026 1026
 			if (isset($registry['mime']) &&
1027 1027
 				(isset($GLOBALS['egw_info']['user']['apps'][$app]) ||
1028 1028
 				isset($registry['app']) && isset($GLOBALS['egw_info']['user']['apps'][$registry['app']])))
1029 1029
 			{
1030
-				foreach($registry['mime'] as $mime => $data)
1030
+				foreach ($registry['mime'] as $mime => $data)
1031 1031
 				{
1032 1032
 					if ($mime == $type) return $data;
1033 1033
 					if ($mime[0] == '/' && preg_match($mime.'i', $type))
@@ -1048,7 +1048,7 @@  discard block
 block discarded – undo
1048 1048
 	 * @param string &$popup=null on return popup size or null
1049 1049
 	 * @return string|array string with EGw relative link, array with get-parameters for '/index.php' or null (directory and not filemanager access)
1050 1050
 	 */
1051
-	static function mime_open($path, $type=null, &$popup=null)
1051
+	static function mime_open($path, $type = null, &$popup = null)
1052 1052
 	{
1053 1053
 		if (is_null($type)) $type = Vfs::mime_content_type($path);
1054 1054
 
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
 				$data[$data['mime_id']] = $path;
1065 1065
 				unset($data['mime_id']);
1066 1066
 			}
1067
-			elseif(isset($data['mime_popup']))
1067
+			elseif (isset($data['mime_popup']))
1068 1068
 			{
1069 1069
 				$popup = $data['mime_popup'];
1070 1070
 			}
@@ -1089,9 +1089,9 @@  discard block
 block discarded – undo
1089 1089
 	 * @param array $link =null link-data for file-attachments
1090 1090
 	 * @return boolean|string false if no popup is used or $app is not registered, otherwise string with the prefered popup size (eg. '640x400)
1091 1091
 	 */
1092
-	static function is_popup($app, $action='view', $link=null)
1092
+	static function is_popup($app, $action = 'view', $link = null)
1093 1093
 	{
1094
-		$popup = self::get_registry($app,$action.'_popup');
1094
+		$popup = self::get_registry($app, $action.'_popup');
1095 1095
 
1096 1096
 		// for files/attachments check mime-registry
1097 1097
 		if ($app == self::VFS_APPNAME && is_array($link) && !empty($link['type']))
@@ -1114,7 +1114,7 @@  discard block
 block discarded – undo
1114 1114
 	 * @param string $name name / key in the registry, eg. 'view'
1115 1115
 	 * @return boolean|string false if $app is not registered, otherwise string with the value for $name
1116 1116
 	 */
1117
-	static function get_registry($app,$name)
1117
+	static function get_registry($app, $name)
1118 1118
 	{
1119 1119
 		$reg = self::$app_register[$app];
1120 1120
 
@@ -1122,7 +1122,7 @@  discard block
 block discarded – undo
1122 1122
 
1123 1123
 		if (!isset($reg[$name]))	// some defaults
1124 1124
 		{
1125
-			switch($name)
1125
+			switch ($name)
1126 1126
 			{
1127 1127
 				case 'name':
1128 1128
 					$reg[$name] = $app;
@@ -1155,16 +1155,16 @@  discard block
 block discarded – undo
1155 1155
 	 * @param boolean $just_the_path =false return url or just the vfs path
1156 1156
 	 * @return string/array path or array with path and relatives, depending on $relatives
1157 1157
 	 */
1158
-	static function vfs_path($app,$id='',$file='',$just_the_path=false)
1158
+	static function vfs_path($app, $id = '', $file = '', $just_the_path = false)
1159 1159
 	{
1160 1160
 		$path = self::VFS_BASEURL;
1161 1161
 
1162 1162
 		if ($app)
1163 1163
 		{
1164
-			if( isset(self::$app_register[$app]) ) {
1164
+			if (isset(self::$app_register[$app])) {
1165 1165
 				$reg = self::$app_register[$app];
1166 1166
 
1167
-				if( isset($reg['file_dir']) ) {
1167
+				if (isset($reg['file_dir'])) {
1168 1168
 					$app = $reg['file_dir'];
1169 1169
 				}
1170 1170
 			}
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
 		}
1184 1184
 		if ($just_the_path)
1185 1185
 		{
1186
-			$path = parse_url($path,PHP_URL_PATH);
1186
+			$path = parse_url($path, PHP_URL_PATH);
1187 1187
 		}
1188 1188
 		else
1189 1189
 		{
@@ -1207,16 +1207,16 @@  discard block
 block discarded – undo
1207 1207
 	 * @param string $comment ='' comment to add to the link
1208 1208
 	 * @return int negative id of egw_sqlfs table as negative link-id's are for vfs attachments
1209 1209
 	 */
1210
-	static function attach_file($app,$id,$file,$comment='')
1210
+	static function attach_file($app, $id, $file, $comment = '')
1211 1211
 	{
1212
-		$entry_dir = self::vfs_path($app,$id);
1212
+		$entry_dir = self::vfs_path($app, $id);
1213 1213
 		if (self::DEBUG)
1214 1214
 		{
1215 1215
 			echo "<p>attach_file: app='$app', id='$id', tmp_name='$file[tmp_name]', name='$file[name]', size='$file[size]', type='$file[type]', path='$file[path]', ip='$file[ip]', comment='$comment', entry_dir='$entry_dir'</p>\n";
1216 1216
 		}
1217
-		if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir,0,true)))
1217
+		if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir, 0, true)))
1218 1218
 		{
1219
-			$Ok = Vfs::copy_uploaded($file, $p=self::vfs_path($app,$id,'',true), $comment, false);	// no is_uploaded_file() check!
1219
+			$Ok = Vfs::copy_uploaded($file, $p = self::vfs_path($app, $id, '', true), $comment, false); // no is_uploaded_file() check!
1220 1220
 			if (!$Ok) error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called Vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok));
1221 1221
 		}
1222 1222
 		else
@@ -1234,24 +1234,24 @@  discard block
 block discarded – undo
1234 1234
 	 * @param string $file VFS path to link to
1235 1235
 	 * @param string $comment ='' comment to add to the link
1236 1236
 	 */
1237
-	static function link_file($app,$id,$file)//,$comment='')
1237
+	static function link_file($app, $id, $file)//,$comment='')
1238 1238
 	{
1239 1239
 		// Don't try to link into app dir if there is no id
1240
-		if(!$id) return;
1240
+		if (!$id) return;
1241 1241
 
1242
-		$app_path = self::vfs_path($app,$id);
1242
+		$app_path = self::vfs_path($app, $id);
1243 1243
 		$ok = true;
1244
-		if (Vfs::file_exists($app_path) || ($ok = Vfs::mkdir($app_path,0,true)))
1244
+		if (Vfs::file_exists($app_path) || ($ok = Vfs::mkdir($app_path, 0, true)))
1245 1245
 		{
1246 1246
 			if (!Vfs::stat($file))
1247 1247
 			{
1248
-				error_log(__METHOD__. ' (Link target ' . Vfs::decodePath($file) . ' not found!');
1248
+				error_log(__METHOD__.' (Link target '.Vfs::decodePath($file).' not found!');
1249 1249
 				return false;
1250 1250
 			}
1251 1251
 		}
1252 1252
 
1253
-		$link = Vfs::concat($app_path,Vfs::basename($file));
1254
-		return Vfs::symlink($file,$link);
1253
+		$link = Vfs::concat($app_path, Vfs::basename($file));
1254
+		return Vfs::symlink($file, $link);
1255 1255
 	}
1256 1256
 	/**
1257 1257
 	 * deletes a single or all attached files of an entry (for all there's no acl check, as the entry probably not exists any more!)
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
 	 * @param string $fname ='' filename
1262 1262
 	 * @return boolean|array false on error ($app or $id not found), array with path as key and boolean result of delete
1263 1263
 	 */
1264
-	static function delete_attached($app,$id='',$fname='')
1264
+	static function delete_attached($app, $id = '', $fname = '')
1265 1265
 	{
1266 1266
 		if ((int)$app > 0)	// is file_id
1267 1267
 		{
@@ -1271,9 +1271,9 @@  discard block
 block discarded – undo
1271 1271
 		{
1272 1272
 			if (empty($app) || empty($id))
1273 1273
 			{
1274
-				return False;	// dont delete more than all attachments of an entry
1274
+				return False; // dont delete more than all attachments of an entry
1275 1275
 			}
1276
-			$url = self::vfs_path($app,$id,$fname);
1276
+			$url = self::vfs_path($app, $id, $fname);
1277 1277
 
1278 1278
 			if (!$fname || !$id)	// we delete the whole entry (or all entries), which probably not exist anymore
1279 1279
 			{
@@ -1286,15 +1286,15 @@  discard block
 block discarded – undo
1286 1286
 			echo '<p>'.__METHOD__."('$app','$id','$fname') url=$url</p>\n";
1287 1287
 		}
1288 1288
 		// Log in history - Need to load it first
1289
-		if((int)$app > 0)
1289
+		if ((int)$app > 0)
1290 1290
 		{
1291 1291
 			$link = self::get_link(-$app);
1292
-			if($link['app2'] && $link['id2'])
1292
+			if ($link['app2'] && $link['id2'])
1293 1293
 			{
1294
-				Storage\History::static_add($link['app2'],$link['id2'],$GLOBALS['egw_info']['user']['account_id'],'~file~','', basename($url));
1294
+				Storage\History::static_add($link['app2'], $link['id2'], $GLOBALS['egw_info']['user']['account_id'], '~file~', '', basename($url));
1295 1295
 			}
1296 1296
 		}
1297
-		if (($Ok = !file_exists($url) || Vfs::remove($url,true)) && ((int)$app > 0 || $fname))
1297
+		if (($Ok = !file_exists($url) || Vfs::remove($url, true)) && ((int)$app > 0 || $fname))
1298 1298
 		{
1299 1299
 			// try removing the dir, in case it's empty
1300 1300
 			@Vfs::rmdir(Vfs::dirname($url));
@@ -1314,14 +1314,14 @@  discard block
 block discarded – undo
1314 1314
 	 * @param string $filename filename
1315 1315
 	 * @return array 'kind' of link-array
1316 1316
 	 */
1317
-	static function info_attached($app,$id,$filename)
1317
+	static function info_attached($app, $id, $filename)
1318 1318
 	{
1319
-		$path = self::vfs_path($app,$id,$filename,true);
1320
-		if (!($stat = Vfs::stat($path,STREAM_URL_STAT_QUIET)))
1319
+		$path = self::vfs_path($app, $id, $filename, true);
1320
+		if (!($stat = Vfs::stat($path, STREAM_URL_STAT_QUIET)))
1321 1321
 		{
1322 1322
 			return false;
1323 1323
 		}
1324
-		return self::fileinfo2link($stat,$path);
1324
+		return self::fileinfo2link($stat, $path);
1325 1325
 	}
1326 1326
 
1327 1327
 	/**
@@ -1330,36 +1330,36 @@  discard block
 block discarded – undo
1330 1330
 	 * @param array|int $fileinfo a row from the vfs-db-table (eg. returned by the vfs ls static function) or a file_id of that table
1331 1331
 	 * @return array a 'kind' of link-array
1332 1332
 	 */
1333
-	static function fileinfo2link($fileinfo,$url=null)
1333
+	static function fileinfo2link($fileinfo, $url = null)
1334 1334
 	{
1335 1335
 		if (!is_array($fileinfo))
1336 1336
 		{
1337 1337
 			$url = Vfs\Sqlfs\StreamWrapper::id2path($fileinfo);
1338
-			if (!($fileinfo = Vfs::url_stat($url,STREAM_URL_STAT_QUIET)))
1338
+			if (!($fileinfo = Vfs::url_stat($url, STREAM_URL_STAT_QUIET)))
1339 1339
 			{
1340 1340
 				return false;
1341 1341
 			}
1342 1342
 		}
1343 1343
 
1344
-		$up = explode('/',$url[0] == '/' ? $url : parse_url($url,PHP_URL_PATH));	// /apps/$app/$id
1344
+		$up = explode('/', $url[0] == '/' ? $url : parse_url($url, PHP_URL_PATH)); // /apps/$app/$id
1345 1345
 		$app = null;
1346 1346
 
1347
-		foreach( self::$app_register as $tapp => $reg ) {
1348
-			if( isset($reg['file_dir']) ) {
1347
+		foreach (self::$app_register as $tapp => $reg) {
1348
+			if (isset($reg['file_dir'])) {
1349 1349
 				$lup = $up;
1350 1350
 
1351 1351
 				unset($lup[0]);
1352 1352
 				unset($lup[1]);
1353 1353
 				reset($lup);
1354 1354
 
1355
-				$fdp = explode('/',$reg['file_dir'][0] == '/' ?
1356
-					$reg['file_dir'] : parse_url($reg['file_dir'],PHP_URL_PATH));
1355
+				$fdp = explode('/', $reg['file_dir'][0] == '/' ?
1356
+					$reg['file_dir'] : parse_url($reg['file_dir'], PHP_URL_PATH));
1357 1357
 
1358 1358
 				$found = true;
1359 1359
 
1360
-				foreach( $fdp as $part ) {
1361
-					if( current($lup) == $part ) {
1362
-						if( next($lup) === false ) {
1360
+				foreach ($fdp as $part) {
1361
+					if (current($lup) == $part) {
1362
+						if (next($lup) === false) {
1363 1363
 							$found = false;
1364 1364
 							break;
1365 1365
 						}
@@ -1370,16 +1370,16 @@  discard block
 block discarded – undo
1370 1370
 					}
1371 1371
 				}
1372 1372
 
1373
-				if( $found ) {
1374
-					$id	= current($lup);
1373
+				if ($found) {
1374
+					$id = current($lup);
1375 1375
 					$app = $tapp;
1376 1376
 					break;
1377 1377
 				}
1378 1378
 			}
1379 1379
 		}
1380 1380
 
1381
-		if( $app === null ) {
1382
-			list(,,$app,$id) = $up;
1381
+		if ($app === null) {
1382
+			list(,, $app, $id) = $up;
1383 1383
 		}
1384 1384
 
1385 1385
 		return array(
@@ -1387,7 +1387,7 @@  discard block
 block discarded – undo
1387 1387
 			'id'        => $fileinfo['name'],
1388 1388
 			'app2'      => $app,
1389 1389
 			'id2'       => $id,
1390
-			'remark'    => '',					// only list_attached currently sets the remark
1390
+			'remark'    => '', // only list_attached currently sets the remark
1391 1391
 			'owner'     => $fileinfo['uid'],
1392 1392
 			'link_id'   => -$fileinfo['ino'],
1393 1393
 			'lastmod'   => $fileinfo['mtime'],
@@ -1403,26 +1403,26 @@  discard block
 block discarded – undo
1403 1403
 	 * @param string $id id in app
1404 1404
 	 * @return array with link_id => 'kind' of link-array pairs
1405 1405
 	 */
1406
-	static function list_attached($app,$id)
1406
+	static function list_attached($app, $id)
1407 1407
 	{
1408
-		$path = self::vfs_path($app,$id);
1408
+		$path = self::vfs_path($app, $id);
1409 1409
 		//error_log(__METHOD__."($app,$id) url=$url");
1410 1410
 
1411
-		if (!($extra = self::get_registry($app,'find_extra'))) $extra = array();
1411
+		if (!($extra = self::get_registry($app, 'find_extra'))) $extra = array();
1412 1412
 
1413 1413
 		// always use regular links stream wrapper here: extended one is unnecessary (slow) for just listing attachments
1414
-		if (substr($path,0,13) == 'stylite.links') $path = substr($path,8);
1414
+		if (substr($path, 0, 13) == 'stylite.links') $path = substr($path, 8);
1415 1415
 
1416 1416
 		$attached = array();
1417
-		if (($url2stats = Vfs::find($path,array('need_mime'=>true,'type'=>'F','url'=>true)+$extra,true)))
1417
+		if (($url2stats = Vfs::find($path, array('need_mime'=>true, 'type'=>'F', 'url'=>true) + $extra, true)))
1418 1418
 		{
1419
-			$props = Vfs::propfind(array_keys($url2stats));	// get the comments
1420
-			foreach($url2stats as $url => &$fileinfo)
1419
+			$props = Vfs::propfind(array_keys($url2stats)); // get the comments
1420
+			foreach ($url2stats as $url => &$fileinfo)
1421 1421
 			{
1422
-				$link = self::fileinfo2link($fileinfo,$url);
1422
+				$link = self::fileinfo2link($fileinfo, $url);
1423 1423
 				if ($props && isset($props[$url]))
1424 1424
 				{
1425
-					foreach($props[$url] as $prop)
1425
+					foreach ($props[$url] as $prop)
1426 1426
 					{
1427 1427
 						if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'] == 'comment')
1428 1428
 						{
@@ -1444,7 +1444,7 @@  discard block
 block discarded – undo
1444 1444
 	 */
1445 1445
 	static private function decode_htmlspecialchars($str)
1446 1446
 	{
1447
-		return str_replace(array('&amp;','&quot;','&lt;','&gt;'),array('&','"','<','>'),$str);
1447
+		return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $str);
1448 1448
 	}
1449 1449
 
1450 1450
 	/**
@@ -1462,18 +1462,18 @@  discard block
 block discarded – undo
1462 1462
 	 * @param string $id id in $app of the updated entry
1463 1463
 	 * @param array $data =null updated data of changed entry, as the read-method of the BO-layer would supply it
1464 1464
 	 */
1465
-	static function notify_update($app,$id,$data=null)
1465
+	static function notify_update($app, $id, $data = null)
1466 1466
 	{
1467
-		self::delete_cache($app,$id);
1467
+		self::delete_cache($app, $id);
1468 1468
 		//error_log(__METHOD__."('$app', $id, $data)");
1469
-		foreach(self::get_links($app,$id,'!'.self::VFS_APPNAME) as $link_id => $link)
1469
+		foreach (self::get_links($app, $id, '!'.self::VFS_APPNAME) as $link_id => $link)
1470 1470
 		{
1471
-			self::notify('update',$link['app'],$link['id'],$app,$id,$link_id,$data);
1471
+			self::notify('update', $link['app'], $link['id'], $app, $id, $link_id, $data);
1472 1472
 		}
1473
-		if($data[Link::OLD_LINK_TITLE] && Json\Response::isJSONResponse())
1473
+		if ($data[Link::OLD_LINK_TITLE] && Json\Response::isJSONResponse())
1474 1474
 		{
1475 1475
 			// Update client side with new title
1476
-			Json\Response::get()->apply('egw.link_title_callback',array(array($app => array($id => self::title($app, $id)))));
1476
+			Json\Response::get()->apply('egw.link_title_callback', array(array($app => array($id => self::title($app, $id)))));
1477 1477
 		}
1478 1478
 	}
1479 1479
 
@@ -1497,7 +1497,7 @@  discard block
 block discarded – undo
1497 1497
 	 * @param string $target_id id in $target_app
1498 1498
 	 * @param array $data =null data of entry in app2 (optional)
1499 1499
 	 */
1500
-	static private function notify($type,$notify_app,$notify_id,$target_app,$target_id,$link_id,$data=null)
1500
+	static private function notify($type, $notify_app, $notify_id, $target_app, $target_id, $link_id, $data = null)
1501 1501
 	{
1502 1502
 		//error_log(__METHOD__."('$type', '$notify_app', $notify_id, '$target_app', $target_id, $link_id, $data)");
1503 1503
 		if ($link_id && isset(self::$app_register[$notify_app]) && isset(self::$app_register[$notify_app]['notify']))
@@ -1524,7 +1524,7 @@  discard block
 block discarded – undo
1524 1524
 	static public function run_notifies()
1525 1525
 	{
1526 1526
 		//error_log(__METHOD__."() count(self::\$notifies)=".count(self::$notifies));
1527
-		while(self::$notifies)
1527
+		while (self::$notifies)
1528 1528
 		{
1529 1529
 			$args = array_shift(self::$notifies);
1530 1530
 			$method = $args['method'];
@@ -1542,11 +1542,11 @@  discard block
 block discarded – undo
1542 1542
 	 */
1543 1543
 	static private function notify_unlink(&$links)
1544 1544
 	{
1545
-		foreach($links as $link)
1545
+		foreach ($links as $link)
1546 1546
 		{
1547 1547
 			// we notify both sides of the link, as the unlink command NOT clearly knows which side initiated the unlink
1548
-			self::notify('unlink',$link['link_app1'],$link['link_id1'],$link['link_app2'],$link['link_id2'],$link['link_id']);
1549
-			self::notify('unlink',$link['link_app2'],$link['link_id2'],$link['link_app1'],$link['link_id1'],$link['link_id']);
1548
+			self::notify('unlink', $link['link_app1'], $link['link_id1'], $link['link_app2'], $link['link_id2'], $link['link_id']);
1549
+			self::notify('unlink', $link['link_app2'], $link['link_id2'], $link['link_app1'], $link['link_id1'], $link['link_id']);
1550 1550
 		}
1551 1551
 	}
1552 1552
 
@@ -1558,9 +1558,9 @@  discard block
 block discarded – undo
1558 1558
 	 * @param string $type ='title' 'title' or 'file_access'
1559 1559
 	 * @return int|string can be null, if cache not yet set
1560 1560
 	 */
1561
-	private static function &get_cache($app,$id,$type = 'title')
1561
+	private static function &get_cache($app, $id, $type = 'title')
1562 1562
 	{
1563
-		switch($type)
1563
+		switch ($type)
1564 1564
 		{
1565 1565
 			case 'title':
1566 1566
 				return self::$title_cache[$app.':'.$id];
@@ -1583,7 +1583,7 @@  discard block
 block discarded – undo
1583 1583
 	 * @param string $title title string or null
1584 1584
 	 * @param int $file_access =null Acl::READ, Acl::EDIT or both or'ed together
1585 1585
 	 */
1586
-	public static function set_cache($app,$id,$title,$file_access=null)
1586
+	public static function set_cache($app, $id, $title, $file_access = null)
1587 1587
 	{
1588 1588
 		//error_log(__METHOD__."($app,$id,$title,$file_access)");
1589 1589
 		if (!is_null($title))
@@ -1602,7 +1602,7 @@  discard block
 block discarded – undo
1602 1602
 	 * @param string $app app-name or null to delete the whole cache
1603 1603
 	 * @param int|string $id id or null to delete only file_access cache of given app (keeps title cache, if app implements file_access!)
1604 1604
 	 */
1605
-	private static function delete_cache($app,$id)
1605
+	private static function delete_cache($app, $id)
1606 1606
 	{
1607 1607
 		unset(self::$title_cache[$app.':'.$id]);
1608 1608
 		unset(self::$file_access_cache[$app.':'.$id]);
@@ -1617,7 +1617,7 @@  discard block
 block discarded – undo
1617 1617
 	 * @param boolean $ignore_mime =false true: return id, even if nothing registered for given mime-type
1618 1618
 	 * @return string|null md5 hash of stored data of server-side supported mime-type or null otherwise
1619 1619
 	 */
1620
-	public static function set_data($mime_type, $method, array $params, $ignore_mime=false)
1620
+	public static function set_data($mime_type, $method, array $params, $ignore_mime = false)
1621 1621
 	{
1622 1622
 		if (!$ignore_mime && (!($info = self::get_mime_info($mime_type)) || empty($info['mime_data'])))
1623 1623
 		{
@@ -1638,7 +1638,7 @@  discard block
 block discarded – undo
1638 1638
 	 * @return mixed null if id is not found or invalid
1639 1639
 	 * @throws Exception\WrongParameter
1640 1640
 	 */
1641
-	public static function get_data($id, $return_resource=false)
1641
+	public static function get_data($id, $return_resource = false)
1642 1642
 	{
1643 1643
 		$data = Cache::getSession(__CLASS__, $id);
1644 1644
 
@@ -1662,7 +1662,7 @@  discard block
 block discarded – undo
1662 1662
 			{
1663 1663
 				$fp = $ret;
1664 1664
 				$ret = '';
1665
-				while(!feof($fp))
1665
+				while (!feof($fp))
1666 1666
 				{
1667 1667
 					$ret .= fread($fp, 8192);
1668 1668
 				}
@@ -1687,42 +1687,42 @@  discard block
 block discarded – undo
1687 1687
 	 * @param int $user =null default null = current user
1688 1688
 	 * @return boolean true if access granted, false otherwise
1689 1689
 	 */
1690
-	static function file_access($app,$id,$required=Acl::READ,$rel_path=null,$user=null)
1690
+	static function file_access($app, $id, $required = Acl::READ, $rel_path = null, $user = null)
1691 1691
 	{
1692 1692
 		// are we called for an other user
1693 1693
 		if ($user && $user != $GLOBALS['egw_info']['user']['account_id'])
1694 1694
 		{
1695 1695
 			// check if app supports file_access WITH 4th $user parameter --> return false if not
1696
-			if (!self::get_registry($app,'file_access_user') || !($method = self::get_registry($app,'file_access')))
1696
+			if (!self::get_registry($app, 'file_access_user') || !($method = self::get_registry($app, 'file_access')))
1697 1697
 			{
1698 1698
 				$ret = false;
1699 1699
 				$err = "(no file_access_user)";
1700 1700
 			}
1701 1701
 			else
1702 1702
 			{
1703
-				$ret = ExecMethod2($method,$id,$required,$rel_path,$user);
1703
+				$ret = ExecMethod2($method, $id, $required, $rel_path, $user);
1704 1704
 				$err = "(from $method)";
1705 1705
 			}
1706 1706
 			//error_log(__METHOD__."('$app',$id,$required,'$rel_path',$user) returning $err ".array2string($ret));
1707 1707
 			return $ret;
1708 1708
 		}
1709 1709
 
1710
-		$cache =& self::get_cache($app,$id,'file_access');
1710
+		$cache = & self::get_cache($app, $id, 'file_access');
1711 1711
 
1712
-		if (!isset($cache) || $required == Acl::EDIT && !($cache & $required))
1712
+		if (!isset($cache) || $required == Acl::EDIT && !($cache&$required))
1713 1713
 		{
1714
-			if(($method = self::get_registry($app,'file_access')))
1714
+			if (($method = self::get_registry($app, 'file_access')))
1715 1715
 			{
1716
-				$cache |= ExecMethod2($method,$id,$required,$rel_path) ? $required|Acl::READ : 0;
1716
+				$cache |= ExecMethod2($method, $id, $required, $rel_path) ? $required|Acl::READ : 0;
1717 1717
 			}
1718 1718
 			else
1719 1719
 			{
1720
-				$cache |= self::title($app,$id) ? Acl::READ|Acl::EDIT : 0;
1720
+				$cache |= self::title($app, $id) ? Acl::READ|Acl::EDIT : 0;
1721 1721
 			}
1722 1722
 			//error_log(__METHOD__."($app,$id,$required,$rel_path) got $cache --> ".($cache & $required ? 'true' : 'false'));
1723 1723
 		}
1724 1724
 		//else error_log(__METHOD__."($app,$id,$required,$rel_path) using cached value $cache --> ".($cache & $required ? 'true' : 'false'));
1725
-		return !!($cache & $required);
1725
+		return !!($cache&$required);
1726 1726
 	}
1727 1727
 }
1728 1728
 Link::init_static();
Please login to merge, or discard this patch.
Braces   +178 added lines, -49 removed lines patch added patch discarded remove patch
@@ -298,10 +298,13 @@  discard block
 block discarded – undo
298 298
 	 */
299 299
 	static function save_session_cache()
300 300
 	{
301
-		if (isset($GLOBALS['egw']->session))	// eg. cron-jobs use it too, without any session
301
+		if (isset($GLOBALS['egw']->session))
302
+		{
303
+			// eg. cron-jobs use it too, without any session
302 304
 		{
303 305
 			//error_log(__METHOD__.'() items in title-cache: '.count(self::$title_cache).' file-access-cache: '.count(self::$file_access_cache));
304 306
 			Cache::setSession(__CLASS__, 'link_title_cache', self::$title_cache);
307
+		}
305 308
 			Cache::setSession(__CLASS__, 'link_file_access_cache', self::$file_access_cache);
306 309
 		}
307 310
 	}
@@ -345,14 +348,20 @@  discard block
 block discarded – undo
345 348
 			$link_id = True;
346 349
 			while ($link_id && list(,$link) = each($app2))
347 350
 			{
348
-				if (!is_array($link))	// check for unlink-marker
351
+				if (!is_array($link))
352
+				{
353
+					// check for unlink-marker
349 354
 				{
350 355
 					//echo "<b>link='$link' is no array</b><br>\n";
351 356
 					continue;
352 357
 				}
353
-				if (is_array($id1) || !$id1)		// create link only in $id1 array
358
+				}
359
+				if (is_array($id1) || !$id1)
360
+				{
361
+					// create link only in $id1 array
354 362
 				{
355 363
 					self::link($app1, $id1, $link['app'], $link['id'], $link['remark'],$link['owner'],$link['lastmod']);
364
+				}
356 365
 					continue;
357 366
 				}
358 367
 				switch ($link['app'])
@@ -376,18 +385,27 @@  discard block
 block discarded – undo
376 385
 						$link_id = Link\Storage::link($app1,$id1,$link['app'],$link['id'],
377 386
 							$link['remark'],$link['owner'],$link['lastmod']);
378 387
 						// notify both sides
379
-						if (!($no_notify&2)) self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id);
380
-						if (!($no_notify&1)) self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id);
388
+						if (!($no_notify&2))
389
+						{
390
+							self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id);
391
+						}
392
+						if (!($no_notify&1))
393
+						{
394
+							self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id);
395
+						}
381 396
 						break;
382 397
 				}
383 398
 			}
384 399
 			return $link_id;
385 400
 		}
386
-		if (is_array($id1) || !$id1)		// create link only in $id1 array
401
+		if (is_array($id1) || !$id1)
402
+		{
403
+			// create link only in $id1 array
387 404
 		{
388 405
 			if (!is_array($id1))
389 406
 			{
390 407
 				$id1 = array( );
408
+		}
391 409
 			}
392 410
 			$link_id = self::temp_link_id($app2,$id2);
393 411
 
@@ -423,8 +441,14 @@  discard block
 block discarded – undo
423 441
 		}
424 442
 		$link_id = Link\Storage::link($app1,$id1,$app2,$id2,$remark,$owner);
425 443
 
426
-		if (!($no_notify&2)) self::notify('link',$app2,$id2,$app1,$id1,$link_id);
427
-		if (!($no_notify&1)) self::notify('link',$app1,$id1,$app2,$id2,$link_id);
444
+		if (!($no_notify&2))
445
+		{
446
+			self::notify('link',$app2,$id2,$app1,$id1,$link_id);
447
+		}
448
+		if (!($no_notify&1))
449
+		{
450
+			self::notify('link',$app1,$id1,$app2,$id2,$link_id);
451
+		}
428 452
 
429 453
 		return $link_id;
430 454
 	}
@@ -456,7 +480,10 @@  discard block
 block discarded – undo
456 480
 	 */
457 481
 	static function get_links($app, $id, $only_app='', $order='link_lastmod DESC',$cache_titles=false, $deleted=false, $limit=null)
458 482
 	{
459
-		if (self::DEBUG) echo "<p>Link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n";
483
+		if (self::DEBUG)
484
+		{
485
+			echo "<p>Link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n";
486
+		}
460 487
 
461 488
 		if (is_array($id) || !$id)
462 489
 		{
@@ -527,7 +554,10 @@  discard block
 block discarded – undo
527 554
 	 */
528 555
 	static function get_links_multiple($app,array $ids,$cache_titles=true,$only_app='',$order='link_lastmod DESC', $deleted=false )
529 556
 	{
530
-		if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n";
557
+		if (self::DEBUG)
558
+		{
559
+			echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n";
560
+		}
531 561
 
532 562
 		if (!$ids)
533 563
 		{
@@ -559,7 +589,10 @@  discard block
 block discarded – undo
559 589
 			{
560 590
 				foreach($targets as $link)
561 591
 				{
562
-					if (is_array($link)) $app_ids[$link['app']][] = $link['id'];
592
+					if (is_array($link))
593
+					{
594
+						$app_ids[$link['app']][] = $link['id'];
595
+					}
563 596
 				}
564 597
 			}
565 598
 			foreach($app_ids as $app => $a_ids)
@@ -589,20 +622,30 @@  discard block
 block discarded – undo
589 622
 		}
590 623
 		if (is_array($id))
591 624
 		{
592
-			if (strpos($app_link_id,':') === false) $app_link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
625
+			if (strpos($app_link_id,':') === false)
626
+			{
627
+				$app_link_id = self::temp_link_id($app2,$id2);
628
+			}
629
+			// create link_id of temporary link, if not given
593 630
 
594
-			if (isset($id[$app_link_id]) && is_array($id[$app_link_id]))	// check for unlinked-marker
631
+			if (isset($id[$app_link_id]) && is_array($id[$app_link_id]))
632
+			{
633
+				// check for unlinked-marker
595 634
 			{
596 635
 				return $id[$app_link_id];
597 636
 			}
637
+			}
598 638
 			return False;
599 639
 		}
600 640
 		if ((int)$app_link_id < 0 || $app_link_id == self::VFS_APPNAME || $app2 == self::VFS_APPNAME)
601 641
 		{
602
-			if ((int)$app_link_id < 0)	// vfs link_id ?
642
+			if ((int)$app_link_id < 0)
643
+			{
644
+				// vfs link_id ?
603 645
 			{
604 646
 				return self::fileinfo2link(-$app_link_id);
605 647
 			}
648
+			}
606 649
 			if ($app_link_id == self::VFS_APPNAME)
607 650
 			{
608 651
 				return self::info_attached($app2,$id2,$id);
@@ -650,10 +693,13 @@  discard block
 block discarded – undo
650 693
 		{
651 694
 			echo "<p>Link::unlink('$link_id','$app',".array2string($id).",'$owner','$app2','$id2', $hold_for_purge)</p>\n";
652 695
 		}
653
-		if ($link_id < 0)	// vfs-link?
696
+		if ($link_id < 0)
697
+		{
698
+			// vfs-link?
654 699
 		{
655 700
 			return self::delete_attached(-$link_id);
656 701
 		}
702
+		}
657 703
 		elseif ($app == self::VFS_APPNAME)
658 704
 		{
659 705
 			return self::delete_attached($app2,$id2,$id);
@@ -692,7 +738,11 @@  discard block
 block discarded – undo
692 738
 
693 739
 			return count($deleted);
694 740
 		}
695
-		if (!$link_id) $link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
741
+		if (!$link_id)
742
+		{
743
+			$link_id = self::temp_link_id($app2,$id2);
744
+		}
745
+		// create link_id of temporary link, if not given
696 746
 
697 747
 		if (isset($id[$link_id]))
698 748
 		{
@@ -718,7 +768,10 @@  discard block
 block discarded – undo
718 768
 		$apps = array();
719 769
 		foreach(self::$app_register as $type => $reg)
720 770
 		{
721
-			if ($must_support && !isset($reg[$must_support])) continue;
771
+			if ($must_support && !isset($reg[$must_support]))
772
+			{
773
+				continue;
774
+			}
722 775
 
723 776
 			list($app) = explode('-', $type);
724 777
 			if ($GLOBALS['egw_info']['user']['apps'][$app])
@@ -756,7 +809,10 @@  discard block
 block discarded – undo
756 809
 		if(strpos($method,'::') !== false)
757 810
 		{
758 811
 			//  workaround for php < 5.3: do NOT call it static, but allow application code to specify static callbacks
759
-			if (version_compare(PHP_VERSION,'5.3','<')) list($class,$method) = explode('::',$method);
812
+			if (version_compare(PHP_VERSION,'5.3','<'))
813
+			{
814
+				list($class,$method) = explode('::',$method);
815
+			}
760 816
 		}
761 817
 		else
762 818
 		{
@@ -768,19 +824,25 @@  discard block
 block discarded – undo
768 824
 			{
769 825
 				$GLOBALS[$class] = new $class();
770 826
 			}
771
-			if (is_object($GLOBALS[$class]))        // use existing instance (put there by a previous CreateObject)
827
+			if (is_object($GLOBALS[$class]))
828
+			{
829
+				// use existing instance (put there by a previous CreateObject)
772 830
 			{
773 831
 				$obj = $GLOBALS[$class];
774 832
 			}
833
+			}
775 834
 			else
776 835
 			{
777 836
 				$obj = CreateObject($app.'.'.$class);
778 837
 			}
779 838
 		}
780
-		if(is_callable($method))        // php5.3+ call
839
+		if(is_callable($method))
840
+		{
841
+			// php5.3+ call
781 842
 		{
782 843
 			$result = call_user_func($method,$pattern,$options);
783 844
 		}
845
+		}
784 846
 		elseif(is_object($obj) && method_exists($obj,$method))
785 847
 		{
786 848
 			$result = $obj->$method($pattern,$options);
@@ -813,12 +875,18 @@  discard block
 block discarded – undo
813 875
 	 */
814 876
 	static function title($app,$id,$link=null)
815 877
 	{
816
-		if (!$id) return '';
878
+		if (!$id)
879
+		{
880
+			return '';
881
+		}
817 882
 
818 883
 		$title =& self::get_cache($app,$id);
819 884
 		if (isset($title) && !empty($title) && !is_array($id))
820 885
 		{
821
-			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n";
886
+			if (self::DEBUG)
887
+			{
888
+				echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n";
889
+			}
822 890
 			return $title;
823 891
 		}
824 892
 		if ($app == self::VFS_APPNAME)
@@ -838,21 +906,33 @@  discard block
 block discarded – undo
838 906
 			{
839 907
 				$title .= ': '.$link['type'] . ' '.Vfs::hsize($link['size']);
840 908
 			}*/
841
-			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (file)</p>\n";
909
+			if (self::DEBUG)
910
+			{
911
+				echo '<p>'.__METHOD__."('$app','$id')='$title' (file)</p>\n";
912
+			}
842 913
 			return $title;
843 914
 		}
844 915
 		if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['title']))
845 916
 		{
846
-			if (self::DEBUG) echo "<p>".__METHOD__."('$app','$id') something is wrong!!!</p>\n";
917
+			if (self::DEBUG)
918
+			{
919
+				echo "<p>".__METHOD__."('$app','$id') something is wrong!!!</p>\n";
920
+			}
847 921
 			return false; //array(); // not sure why it should return an array on failure, as the description states boolean/string
848 922
 		}
849 923
 		$method = $reg['title'];
850 924
 
851
-		if (true) $title = ExecMethod($method,$id);
925
+		if (true)
926
+		{
927
+			$title = ExecMethod($method,$id);
928
+		}
852 929
 
853
-		if ($id && is_null($title))	// $app,$id has been deleted ==> unlink all links to it
930
+		if ($id && is_null($title))
931
+		{
932
+			// $app,$id has been deleted ==> unlink all links to it
854 933
 		{
855 934
 			static $unlinking = array();
935
+		}
856 936
 			// check if we are already trying to unlink the entry, to avoid an infinit recursion
857 937
 			if (!isset($unlinking[$app]) || !isset($unlinking[$app][$id]))
858 938
 			{
@@ -860,10 +940,16 @@  discard block
 block discarded – undo
860 940
 				self::unlink(0,$app,$id);
861 941
 				unset($unlinking[$app][$id]);
862 942
 			}
863
-			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n";
943
+			if (self::DEBUG)
944
+			{
945
+				echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n";
946
+			}
864 947
 			return False;
865 948
 		}
866
-		if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from $method)</p>\n";
949
+		if (self::DEBUG)
950
+		{
951
+			echo '<p>'.__METHOD__."('$app','$id')='$title' (from $method)</p>\n";
952
+		}
867 953
 
868 954
 		return $title;
869 955
 	}
@@ -1029,7 +1115,10 @@  discard block
 block discarded – undo
1029 1115
 			{
1030 1116
 				foreach($registry['mime'] as $mime => $data)
1031 1117
 				{
1032
-					if ($mime == $type) return $data;
1118
+					if ($mime == $type)
1119
+					{
1120
+						return $data;
1121
+					}
1033 1122
 					if ($mime[0] == '/' && preg_match($mime.'i', $type))
1034 1123
 					{
1035 1124
 						$wildcard_mime = $data;
@@ -1050,7 +1139,10 @@  discard block
 block discarded – undo
1050 1139
 	 */
1051 1140
 	static function mime_open($path, $type=null, &$popup=null)
1052 1141
 	{
1053
-		if (is_null($type)) $type = Vfs::mime_content_type($path);
1142
+		if (is_null($type))
1143
+		{
1144
+			$type = Vfs::mime_content_type($path);
1145
+		}
1054 1146
 
1055 1147
 		if (($data = self::get_mime_info($type)))
1056 1148
 		{
@@ -1118,14 +1210,20 @@  discard block
 block discarded – undo
1118 1210
 	{
1119 1211
 		$reg = self::$app_register[$app];
1120 1212
 
1121
-		if (!isset($reg)) return false;
1213
+		if (!isset($reg))
1214
+		{
1215
+			return false;
1216
+		}
1122 1217
 
1123
-		if (!isset($reg[$name]))	// some defaults
1218
+		if (!isset($reg[$name]))
1219
+		{
1220
+			// some defaults
1124 1221
 		{
1125 1222
 			switch($name)
1126 1223
 			{
1127 1224
 				case 'name':
1128 1225
 					$reg[$name] = $app;
1226
+		}
1129 1227
 					break;
1130 1228
 				case 'icon':
1131 1229
 					if (isset($GLOBALS['egw_info']['apps'][$app]['icon']))
@@ -1161,10 +1259,12 @@  discard block
 block discarded – undo
1161 1259
 
1162 1260
 		if ($app)
1163 1261
 		{
1164
-			if( isset(self::$app_register[$app]) ) {
1262
+			if( isset(self::$app_register[$app]) )
1263
+			{
1165 1264
 				$reg = self::$app_register[$app];
1166 1265
 
1167
-				if( isset($reg['file_dir']) ) {
1266
+				if( isset($reg['file_dir']) )
1267
+				{
1168 1268
 					$app = $reg['file_dir'];
1169 1269
 				}
1170 1270
 			}
@@ -1217,7 +1317,10 @@  discard block
 block discarded – undo
1217 1317
 		if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir,0,true)))
1218 1318
 		{
1219 1319
 			$Ok = Vfs::copy_uploaded($file, $p=self::vfs_path($app,$id,'',true), $comment, false);	// no is_uploaded_file() check!
1220
-			if (!$Ok) error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called Vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok));
1320
+			if (!$Ok)
1321
+			{
1322
+				error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called Vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok));
1323
+			}
1221 1324
 		}
1222 1325
 		else
1223 1326
 		{
@@ -1237,7 +1340,10 @@  discard block
 block discarded – undo
1237 1340
 	static function link_file($app,$id,$file)//,$comment='')
1238 1341
 	{
1239 1342
 		// Don't try to link into app dir if there is no id
1240
-		if(!$id) return;
1343
+		if(!$id)
1344
+		{
1345
+			return;
1346
+		}
1241 1347
 
1242 1348
 		$app_path = self::vfs_path($app,$id);
1243 1349
 		$ok = true;
@@ -1263,10 +1369,13 @@  discard block
 block discarded – undo
1263 1369
 	 */
1264 1370
 	static function delete_attached($app,$id='',$fname='')
1265 1371
 	{
1266
-		if ((int)$app > 0)	// is file_id
1372
+		if ((int)$app > 0)
1373
+		{
1374
+			// is file_id
1267 1375
 		{
1268 1376
 			$url = Vfs::resolve_url(Vfs\Sqlfs\StreamWrapper::id2path($app));
1269 1377
 		}
1378
+		}
1270 1379
 		else
1271 1380
 		{
1272 1381
 			if (empty($app) || empty($id))
@@ -1275,9 +1384,12 @@  discard block
 block discarded – undo
1275 1384
 			}
1276 1385
 			$url = self::vfs_path($app,$id,$fname);
1277 1386
 
1278
-			if (!$fname || !$id)	// we delete the whole entry (or all entries), which probably not exist anymore
1387
+			if (!$fname || !$id)
1388
+			{
1389
+				// we delete the whole entry (or all entries), which probably not exist anymore
1279 1390
 			{
1280 1391
 				$current_is_root = Vfs::$is_root;
1392
+			}
1281 1393
 				Vfs::$is_root = true;
1282 1394
 			}
1283 1395
 		}
@@ -1344,8 +1456,10 @@  discard block
 block discarded – undo
1344 1456
 		$up = explode('/',$url[0] == '/' ? $url : parse_url($url,PHP_URL_PATH));	// /apps/$app/$id
1345 1457
 		$app = null;
1346 1458
 
1347
-		foreach( self::$app_register as $tapp => $reg ) {
1348
-			if( isset($reg['file_dir']) ) {
1459
+		foreach( self::$app_register as $tapp => $reg )
1460
+		{
1461
+			if( isset($reg['file_dir']) )
1462
+			{
1349 1463
 				$lup = $up;
1350 1464
 
1351 1465
 				unset($lup[0]);
@@ -1357,20 +1471,25 @@  discard block
 block discarded – undo
1357 1471
 
1358 1472
 				$found = true;
1359 1473
 
1360
-				foreach( $fdp as $part ) {
1361
-					if( current($lup) == $part ) {
1362
-						if( next($lup) === false ) {
1474
+				foreach( $fdp as $part )
1475
+				{
1476
+					if( current($lup) == $part )
1477
+					{
1478
+						if( next($lup) === false )
1479
+						{
1363 1480
 							$found = false;
1364 1481
 							break;
1365 1482
 						}
1366 1483
 					}
1367
-					else {
1484
+					else
1485
+					{
1368 1486
 						$found = false;
1369 1487
 						break;
1370 1488
 					}
1371 1489
 				}
1372 1490
 
1373
-				if( $found ) {
1491
+				if( $found )
1492
+				{
1374 1493
 					$id	= current($lup);
1375 1494
 					$app = $tapp;
1376 1495
 					break;
@@ -1378,7 +1497,8 @@  discard block
 block discarded – undo
1378 1497
 			}
1379 1498
 		}
1380 1499
 
1381
-		if( $app === null ) {
1500
+		if( $app === null )
1501
+		{
1382 1502
 			list(,,$app,$id) = $up;
1383 1503
 		}
1384 1504
 
@@ -1408,10 +1528,16 @@  discard block
 block discarded – undo
1408 1528
 		$path = self::vfs_path($app,$id);
1409 1529
 		//error_log(__METHOD__."($app,$id) url=$url");
1410 1530
 
1411
-		if (!($extra = self::get_registry($app,'find_extra'))) $extra = array();
1531
+		if (!($extra = self::get_registry($app,'find_extra')))
1532
+		{
1533
+			$extra = array();
1534
+		}
1412 1535
 
1413 1536
 		// always use regular links stream wrapper here: extended one is unnecessary (slow) for just listing attachments
1414
-		if (substr($path,0,13) == 'stylite.links') $path = substr($path,8);
1537
+		if (substr($path,0,13) == 'stylite.links')
1538
+		{
1539
+			$path = substr($path,8);
1540
+		}
1415 1541
 
1416 1542
 		$attached = array();
1417 1543
 		if (($url2stats = Vfs::find($path,array('need_mime'=>true,'type'=>'F','url'=>true)+$extra,true)))
@@ -1648,7 +1774,10 @@  discard block
 block discarded – undo
1648 1774
 		}
1649 1775
 		$ret = call_user_func_array('ExecMethod2', $data);
1650 1776
 
1651
-		if (is_resource($ret)) fseek($ret, 0);
1777
+		if (is_resource($ret))
1778
+		{
1779
+			fseek($ret, 0);
1780
+		}
1652 1781
 
1653 1782
 		if ($return_resource != is_resource($ret))
1654 1783
 		{
Please login to merge, or discard this patch.
api/src/Link/Storage.php 5 patches
Doc Comments   +6 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,6 +176,11 @@  discard block
 block discarded – undo
176 176
 		return is_array($id) ? $links : ($links[$id] ? $links[$id] : array());
177 177
 	}
178 178
 
179
+	/**
180
+	 * @param boolean $left
181
+	 * @param string $only_app
182
+	 * @param boolean $not_only
183
+	 */
179 184
 	private static function _add2links($row,$left,$only_app,$not_only,array &$links)
180 185
 	{
181 186
 		$linked_app = $left ? $row['link_app2'] : $row['link_app1'];
@@ -206,7 +211,7 @@  discard block
 block discarded – undo
206 211
 	 * @param string $id ='' id in $app, if no integer link_id given in $app_link_id
207 212
 	 * @param string $app2 ='' appname of 2. endpoint of the link, if no integer link_id given in $app_link_id
208 213
 	 * @param string $id2 ='' id in $app2, if no integer link_id given in $app_link_id
209
-	 * @return array with link-data or False
214
+	 * @return string with link-data or False
210 215
 	 */
211 216
 	static function get_link($app_link_id,$id='',$app2='',$id2='')
212 217
 	{
Please login to merge, or discard this patch.
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 			echo "<p>solink.link('$app1',$id1,'$app2',$id2,'$remark',$owner)</p>\n";
67 67
 		}
68 68
 		if ($app1 == $app2 && $id1 == $id2 ||
69
-		    $id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
69
+			$id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
70 70
 		{
71 71
 			return False;	// dont link to self or other nosense
72 72
 		}
@@ -412,26 +412,26 @@  discard block
 block discarded – undo
412 412
 			array('table'=>self::TABLE,
413 413
 				'cols'=>'c.*,b.link_app1 AS app3,b.link_id1 AS id3,b.link_id AS link3',
414 414
 				'where'=>'a.link_app1='.self::$db->quote($app).' AND c.link_app2='.self::$db->quote($target_app).
415
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
416
-                        	'join'=>" a
415
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
416
+							'join'=>" a
417 417
                         		JOIN $table b ON a.link_id2=b.link_id1 AND a.link_app2=b.link_app1
418 418
                        			JOIN $table c ON a.link_id1=c.link_id1 AND a.link_app1=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app2 AND c.link_id2=b.link_id2",
419 419
 			),
420 420
 			// retrieve the type of links, where the relation is realized as timesheet->infolog/tracker and projectmanager->timesheet
421 421
 			array('table'=>self::TABLE,
422 422
 				'cols'=>'b.link_id, b.link_app2 as app1, b.link_id2 as id1, b.link_app1 as app2, b.link_id1 as id2, b.link_remark,b.link_lastmod,b.link_owner,b.deleted,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
423
-                       		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
424
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
425
-                        	'join'=>" a
423
+					   		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
424
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
425
+							'join'=>" a
426 426
                         		JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
427 427
                         		JOIN $table c ON a.link_id2=c.link_id1 AND a.link_app2=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app1 AND c.link_id2=b.link_id1",
428 428
 			),
429 429
 			// retrieve the type of links, where the relation is realized as timesheet->projectmanager and infolog->timesheet
430 430
 			array('table'=>self::TABLE,
431 431
 				'cols'=>'a.*,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
432
-                     		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
433
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
434
-                       		'join'=>" a
432
+					 		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
433
+								(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
434
+					   		'join'=>" a
435 435
                        			JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
436 436
                         		JOIN $table c ON a.link_id2=c.link_id2 AND a.link_app2=c.link_app2 AND a.link_id!=c.link_id AND c.link_app1=b.link_app1 AND c.link_id1=b.link_id1",
437 437
 			),
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 * @param int $lastmod =0 timestamp of last modification (defaults to now=time())
60 60
 	 * @return int/boolean False (for db or param-error) or on success link_id (Please not the return-value of $id1)
61 61
 	 */
62
-	static function link( $app1,&$id1,$app2,$id2='',$remark='',$owner=0,$lastmod=0 )
62
+	static function link($app1, &$id1, $app2, $id2 = '', $remark = '', $owner = 0, $lastmod = 0)
63 63
 	{
64 64
 		if (self::DEBUG)
65 65
 		{
@@ -68,21 +68,21 @@  discard block
 block discarded – undo
68 68
 		if ($app1 == $app2 && $id1 == $id2 ||
69 69
 		    $id1 == '' || $id2 == '' || $app1 == '' || $app2 == '')
70 70
 		{
71
-			return False;	// dont link to self or other nosense
71
+			return False; // dont link to self or other nosense
72 72
 		}
73
-		if (($link = self::get_link($app1,$id1,$app2,$id2)))
73
+		if (($link = self::get_link($app1, $id1, $app2, $id2)))
74 74
 		{
75 75
 			if ($link['link_remark'] != $remark)
76 76
 			{
77
-				self::update_remark($link['link_id'],$remark);
77
+				self::update_remark($link['link_id'], $remark);
78 78
 			}
79
-			return $link['link_id'];	// link alread exist
79
+			return $link['link_id']; // link alread exist
80 80
 		}
81 81
 		if (!$owner)
82 82
 		{
83 83
 			$owner = $GLOBALS['egw_info']['user']['account_id'];
84 84
 		}
85
-		return self::$db->insert(self::TABLE,array(
85
+		return self::$db->insert(self::TABLE, array(
86 86
 				'link_app1'		=> $app1,
87 87
 				'link_id1'		=> $id1,
88 88
 				'link_app2'		=> $app2,
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 				'link_remark'	=> $remark,
91 91
 				'link_lastmod'	=> $lastmod ? $lastmod : time(),
92 92
 				'link_owner'	=> $owner,
93
-			),False,__LINE__,__FILE__) ? self::$db->get_last_insert_id(self::TABLE,'link_id') : false;
93
+			), False, __LINE__, __FILE__) ? self::$db->get_last_insert_id(self::TABLE, 'link_id') : false;
94 94
 	}
95 95
 
96 96
 	/**
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
 	 * @param string $remark new text for the remark
101 101
 	 * @return boolean true on success, else false
102 102
 	 */
103
-	static function update_remark($link_id,$remark)
103
+	static function update_remark($link_id, $remark)
104 104
 	{
105
-		return self::$db->update(self::TABLE,array(
105
+		return self::$db->update(self::TABLE, array(
106 106
 				'link_remark'	=> $remark,
107 107
 				'link_lastmod'	=> time(),
108
-			),array(
108
+			), array(
109 109
 				'link_id'	=> $link_id,
110
-			),__LINE__,__FILE__);
110
+			), __LINE__, __FILE__);
111 111
 	}
112 112
 
113 113
 	/**
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 	 * @param int|array $limit =null number of entries to return, default null = all or array(offset, num_rows) to return num_rows starting from offset
122 122
 	 * @return array id => links pairs if $id is an array or just the links (only_app: ids) or empty array if no matching links found
123 123
 	 */
124
-	static function get_links($app, $id, $only_app='', $order='link_lastmod DESC', $deleted=false, $limit=null)
124
+	static function get_links($app, $id, $only_app = '', $order = 'link_lastmod DESC', $deleted = false, $limit = null)
125 125
 	{
126 126
 		if (self::DEBUG)
127 127
 		{
128
-			echo "<p>solink.get_links($app,".print_r($id,true).",$only_app,$order,$deleted)</p>\n";
128
+			echo "<p>solink.get_links($app,".print_r($id, true).",$only_app,$order,$deleted)</p>\n";
129 129
 		}
130 130
 		if (($not_only = $only_app[0] == '!'))
131 131
 		{
132
-			$only_app = substr($only_app,1);
132
+			$only_app = substr($only_app, 1);
133 133
 		}
134 134
 
135 135
 		$offset = false;
@@ -137,32 +137,32 @@  discard block
 block discarded – undo
137 137
 		{
138 138
 			list($offset, $limit) = $limit;
139 139
 		}
140
-		elseif($limit)
140
+		elseif ($limit)
141 141
 		{
142 142
 			$offset = 0;
143 143
 		}
144 144
 
145 145
 		$links = array();
146 146
 		try {
147
-			foreach(self::$db->select(self::TABLE, '*', self::$db->expression(self::TABLE, '((', array(
147
+			foreach (self::$db->select(self::TABLE, '*', self::$db->expression(self::TABLE, '((', array(
148 148
 						'link_app1'	=> $app,
149 149
 						'link_id1'	=> $id,
150
-					),') OR (',array(
150
+					), ') OR (', array(
151 151
 						'link_app2'	=> $app,
152 152
 						'link_id2'	=> $id,
153
-					),'))',
153
+					), '))',
154 154
 					$deleted ? '' : ' AND deleted IS NULL'
155 155
 				), __LINE__, __FILE__, $offset, $order ? " ORDER BY $order" : '', 'phpgwapi', $limit) as $row)
156 156
 			{
157 157
 				// check if left side (1) is one of our targets --> add it
158
-				if ($row['link_app1'] == $app && in_array($row['link_id1'],(array)$id))
158
+				if ($row['link_app1'] == $app && in_array($row['link_id1'], (array)$id))
159 159
 				{
160
-					self::_add2links($row,true,$only_app,$not_only,$links);
160
+					self::_add2links($row, true, $only_app, $not_only, $links);
161 161
 				}
162 162
 				// check if right side (2) is one of our targets --> add it (both can be true for multiple targets!)
163
-				if ($row['link_app2'] == $app && in_array($row['link_id2'],(array)$id))
163
+				if ($row['link_app2'] == $app && in_array($row['link_id2'], (array)$id))
164 164
 				{
165
-					self::_add2links($row,false,$only_app,$not_only,$links);
165
+					self::_add2links($row, false, $only_app, $not_only, $links);
166 166
 				}
167 167
 			}
168 168
 			// if query returns exactly limit rows, we assume there are more and therefore set self::$limit_exceeded
@@ -170,18 +170,18 @@  discard block
 block discarded – undo
170 170
 		}
171 171
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
172 172
 		// caused by non-ascii chars compared with ascii field uid
173
-		catch(Api\Db\Exception $e) {
173
+		catch (Api\Db\Exception $e) {
174 174
 			_egw_log_exception($e);
175 175
 		}
176 176
 		return is_array($id) ? $links : ($links[$id] ? $links[$id] : array());
177 177
 	}
178 178
 
179
-	private static function _add2links($row,$left,$only_app,$not_only,array &$links)
179
+	private static function _add2links($row, $left, $only_app, $not_only, array &$links)
180 180
 	{
181 181
 		$linked_app = $left ? $row['link_app2'] : $row['link_app1'];
182 182
 		$linked_id  = $left ? $row['link_id2'] : $row['link_id1'];
183 183
 		$app_id = $left ? $row['link_id1'] : $row['link_id2'];
184
-		list($app) = explode('-',$linked_app);
184
+		list($app) = explode('-', $linked_app);
185 185
 		if ($only_app && $not_only == ($linked_app == $only_app) || !$GLOBALS['egw_info']['user']['apps'][$app])
186 186
 		{
187 187
 			#echo "$linked_app == $only_app, ";var_dump($linked_app == $only_app);echo "	->dont return a link<br>";
@@ -208,13 +208,13 @@  discard block
 block discarded – undo
208 208
 	 * @param string $id2 ='' id in $app2, if no integer link_id given in $app_link_id
209 209
 	 * @return array with link-data or False
210 210
 	 */
211
-	static function get_link($app_link_id,$id='',$app2='',$id2='')
211
+	static function get_link($app_link_id, $id = '', $app2 = '', $id2 = '')
212 212
 	{
213 213
 		if (self::DEBUG)
214 214
 		{
215 215
 			echo "<p>solink.get_link('$app_link_id',$id,'$app2','$id2')</p>\n";
216 216
 		}
217
-		if ((int) $app_link_id > 0)
217
+		if ((int)$app_link_id > 0)
218 218
 		{
219 219
 			$where = array('link_id' => $app_link_id);
220 220
 		}
@@ -224,24 +224,24 @@  discard block
 block discarded – undo
224 224
 			{
225 225
 				return False;
226 226
 			}
227
-			$where = self::$db->expression(self::TABLE,'(',array(
227
+			$where = self::$db->expression(self::TABLE, '(', array(
228 228
 					'link_app1'	=> $app_link_id,
229 229
 					'link_id1'	=> $id,
230 230
 					'link_app2'	=> $app2,
231 231
 					'link_id2'	=> $id2,
232
-				),') OR (',array(
232
+				), ') OR (', array(
233 233
 					'link_app2'	=> $app_link_id,
234 234
 					'link_id2'	=> $id,
235 235
 					'link_app1'	=> $app2,
236 236
 					'link_id1'	=> $id2,
237
-				),')');
237
+				), ')');
238 238
 		}
239 239
 		try {
240
-			return self::$db->select(self::TABLE,'*',$where,__LINE__,__FILE__)->fetch(ADODB_FETCH_ASSOC);
240
+			return self::$db->select(self::TABLE, '*', $where, __LINE__, __FILE__)->fetch(ADODB_FETCH_ASSOC);
241 241
 		}
242 242
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
243 243
 		// caused by non-ascii chars compared with ascii field uid
244
-		catch(Api\Db\Exception $e) {
244
+		catch (Api\Db\Exception $e) {
245 245
 			_egw_log_exception($e);
246 246
 		}
247 247
 		return false;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete of linked entry
260 260
 	 * @return array with deleted links
261 261
 	 */
262
-	static function unlink($link_id,$app='',$id='',$owner=0,$app2='',$id2='',$hold_for_purge=false)
262
+	static function unlink($link_id, $app = '', $id = '', $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false)
263 263
 	{
264 264
 		if (self::DEBUG)
265 265
 		{
@@ -284,21 +284,21 @@  discard block
 block discarded – undo
284 284
 					$check1['link_id1'] = $id;
285 285
 					$check2['link_id2'] = $id;
286 286
 				}
287
-				$where = self::$db->expression(self::TABLE,'((',$check1,') OR (',$check2,'))');
287
+				$where = self::$db->expression(self::TABLE, '((', $check1, ') OR (', $check2, '))');
288 288
 			}
289 289
 			elseif ($app != '' && $app2 != '')
290 290
 			{
291
-				$where = self::$db->expression(self::TABLE,'(',array(
291
+				$where = self::$db->expression(self::TABLE, '(', array(
292 292
 						'link_app1'	=> $app,
293 293
 						'link_id1'	=> $id,
294 294
 						'link_app2'	=> $app2,
295 295
 						'link_id2'	=> $id2,
296
-					),') OR (',array(
296
+					), ') OR (', array(
297 297
 						'link_app1'	=> $app2,
298 298
 						'link_id1'	=> $id2,
299 299
 						'link_app2'	=> $app,
300 300
 						'link_id2'	=> $id,
301
-					),')');
301
+					), ')');
302 302
 			}
303 303
 			if ($owner)
304 304
 			{
@@ -308,25 +308,25 @@  discard block
 block discarded – undo
308 308
 		}
309 309
 		$deleted = array();
310 310
 		try {
311
-			foreach(self::$db->select(self::TABLE,'*',$where,__LINE__,__FILE__) as $row)
311
+			foreach (self::$db->select(self::TABLE, '*', $where, __LINE__, __FILE__) as $row)
312 312
 			{
313 313
 				$deleted[] = $row;
314 314
 			}
315
-			if($hold_for_purge)
315
+			if ($hold_for_purge)
316 316
 			{
317
-				self::$db->update(self::TABLE,array(
317
+				self::$db->update(self::TABLE, array(
318 318
 					'deleted' => time(),
319 319
 					'link_lastmod' => time(),
320
-				), $where, __LINE__,__FILE__);
320
+				), $where, __LINE__, __FILE__);
321 321
 			}
322 322
 			else
323 323
 			{
324
-				self::$db->delete(self::TABLE,$where,__LINE__,__FILE__);
324
+				self::$db->delete(self::TABLE, $where, __LINE__, __FILE__);
325 325
 			}
326 326
 		}
327 327
 		// catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267)
328 328
 		// caused by non-ascii chars compared with ascii field uid
329
-		catch(Api\Db\Exception $e) {
329
+		catch (Api\Db\Exception $e) {
330 330
 			_egw_log_exception($e);
331 331
 		}
332 332
 
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
 			$check1['link_id1'] = $id;
358 358
 			$check2['link_id2'] = $id;
359 359
 		}
360
-		$where = self::$db->expression(self::TABLE,'((',$check1,') OR (',$check2,'))');
361
-		self::$db->update(self::TABLE,array('deleted'=> null), $where, __LINE__,__FILE__);
360
+		$where = self::$db->expression(self::TABLE, '((', $check1, ') OR (', $check2, '))');
361
+		self::$db->update(self::TABLE, array('deleted'=> null), $where, __LINE__, __FILE__);
362 362
 	}
363 363
 
364 364
 	/**
@@ -371,13 +371,13 @@  discard block
 block discarded – undo
371 371
 	 * @param int $new_owner account_id of new owner
372 372
 	 * @return int number of links changed
373 373
 	 */
374
-	static function chown($owner,$new_owner)
374
+	static function chown($owner, $new_owner)
375 375
 	{
376
-		if ((int)$owner <= 0 || (int) $new_owner <= 0)
376
+		if ((int)$owner <= 0 || (int)$new_owner <= 0)
377 377
 		{
378 378
 			return 0;
379 379
 		}
380
-		self::$db->update(self::TABLE,array('owner'=>$new_owner),array('owner'=>$owner),__LINE__,__FILE__);
380
+		self::$db->update(self::TABLE, array('owner'=>$new_owner), array('owner'=>$owner), __LINE__, __FILE__);
381 381
 
382 382
 		return self::$db->affected_rows();
383 383
 	}
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
 	 * @param int|array $limit =null number of entries to return, default null = all or array(offset, num_rows) to return num_rows starting from offset
405 405
 	 * @return array with links from entries from $app to $target_app/$target_id plus the other (b) link_id/app/id in the keys 'link3'/'app3'/'id3'
406 406
 	 */
407
-	static function get_3links($app, $target_app, $target_id=null, $just_app_ids=false, $order='link_lastmod DESC', $limit=null)
407
+	static function get_3links($app, $target_app, $target_id = null, $just_app_ids = false, $order = 'link_lastmod DESC', $limit = null)
408 408
 	{
409 409
 		$table = self::TABLE;
410
-		$arrayofselects=array(
410
+		$arrayofselects = array(
411 411
 			// retrieve the type of links, where the relation is realized as timesheet->infolog/tracker via infolog->projectmanager to timesheet->projectmanager
412 412
 			array('table'=>self::TABLE,
413 413
 				'cols'=>'c.*,b.link_app1 AS app3,b.link_id1 AS id3,b.link_id AS link3',
414 414
 				'where'=>'a.link_app1='.self::$db->quote($app).' AND c.link_app2='.self::$db->quote($target_app).
415
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))),
415
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND c.', array('link_id2' => $target_id))),
416 416
                         	'join'=>" a
417 417
                         		JOIN $table b ON a.link_id2=b.link_id1 AND a.link_app2=b.link_app1
418 418
                        			JOIN $table c ON a.link_id1=c.link_id1 AND a.link_app1=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app2 AND c.link_id2=b.link_id2",
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 			array('table'=>self::TABLE,
422 422
 				'cols'=>'b.link_id, b.link_app2 as app1, b.link_id2 as id1, b.link_app1 as app2, b.link_id1 as id2, b.link_remark,b.link_lastmod,b.link_owner,b.deleted,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
423 423
                        		'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app).
424
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))),
424
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND b.', array('link_id1' => $target_id))),
425 425
                         	'join'=>" a
426 426
                         		JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
427 427
                         		JOIN $table c ON a.link_id2=c.link_id1 AND a.link_app2=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app1 AND c.link_id2=b.link_id1",
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 			array('table'=>self::TABLE,
431 431
 				'cols'=>'a.*,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3',
432 432
                      		'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app).
433
-                        		(!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))),
433
+                        		(!$target_id ? '' : self::$db->expression(self::TABLE, ' AND a.', array('link_id2' => $target_id))),
434 434
                        		'join'=>" a
435 435
                        			JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2
436 436
                         		JOIN $table c ON a.link_id2=c.link_id2 AND a.link_app2=c.link_app2 AND a.link_id!=c.link_id AND c.link_app1=b.link_app1 AND c.link_id1=b.link_id1",
@@ -442,17 +442,17 @@  discard block
 block discarded – undo
442 442
 		{
443 443
 			list($offset, $limit) = $limit;
444 444
 		}
445
-		elseif($limit)
445
+		elseif ($limit)
446 446
 		{
447 447
 			$offset = 0;
448 448
 		}
449 449
 
450 450
 		$links = array();
451
-		foreach(self::$db->union($arrayofselects, __LINE__, __FILE__, $order, $offset, $limit) as $row)
451
+		foreach (self::$db->union($arrayofselects, __LINE__, __FILE__, $order, $offset, $limit) as $row)
452 452
 		{
453 453
 			if ($just_app_ids)
454 454
 			{
455
-				if ($row['link_app1'] == $target_app && (is_null($target_id) || in_array($row['link_id1'],(array)$target_id)))
455
+				if ($row['link_app1'] == $target_app && (is_null($target_id) || in_array($row['link_id1'], (array)$target_id)))
456 456
 				{
457 457
 					$links[$row['link_id']] = $row['link_id2'];
458 458
 				}
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 			}
464 464
 			else
465 465
 			{
466
-				$links[] = Api\Db::strip_array_keys($row,'link_');
466
+				$links[] = Api\Db::strip_array_keys($row, 'link_');
467 467
 			}
468 468
 		}
469 469
 		// if query returns exactly limit rows, we assume there are more and therefore set self::$limit_exceeded
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 */
478 478
 	static function init_static( )
479 479
 	{
480
-		self::$db     = $GLOBALS['egw']->db;
480
+		self::$db = $GLOBALS['egw']->db;
481 481
 	}
482 482
 }
483 483
 Storage::init_static();
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -302,7 +302,10 @@
 block discarded – undo
302 302
 			}
303 303
 			if ($owner)
304 304
 			{
305
-				if ($app) $where = array($where);
305
+				if ($app)
306
+				{
307
+					$where = array($where);
308
+				}
306 309
 				$where['link_owner'] = $owner;
307 310
 			}
308 311
 		}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -269,7 +269,7 @@
 block discarded – undo
269 269
 		{
270 270
 			$where = array('link_id' => $link_id);
271 271
 		}
272
-		elseif ($app == '' AND $owner == '')
272
+		elseif ($app == '' and $owner == '')
273 273
 		{
274 274
 			return 0;
275 275
 		}
Please login to merge, or discard this patch.
api/src/Mail.php 4 patches
Doc Comments   +17 added lines, -13 removed lines patch added patch discarded remove patch
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 	 * forceEAProfileLoad
430 430
 	 * used to force the load of a specific emailadmin profile; we assume administrative use only (as of now)
431 431
 	 * @param int $_profile_id
432
-	 * @return object instance of Mail (by reference)
432
+	 * @return Mail instance of Mail (by reference)
433 433
 	 */
434 434
 	public static function &forceEAProfileLoad($_profile_id)
435 435
 	{
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 	/**
705 705
 	 * Get all identities of given mailaccount
706 706
 	 *
707
-	 * @param int|Mail\Account $account account-object or acc_id
707
+	 * @param integer $account account-object or acc_id
708 708
 	 * @return array - array(email=>realname)
709 709
 	 */
710 710
 	function getAccountIdentities($account)
@@ -1289,7 +1289,7 @@  discard block
 block discarded – undo
1289 1289
 	 * @param array $_filter filter to apply to getSortedList
1290 1290
 	 * @param mixed $_thisUIDOnly = null, if given fetch the headers of this uid only (either one, or array of uids)
1291 1291
 	 * @param boolean $_cacheResult = true try touse the cache of getSortedList
1292
-	 * @param mixed $_fetchPreviews = false (boolean/int) fetch part of the body of the messages requested (if integer the number is assumed to be the number of chars to be returned for preview; if set to true 300 chars are returned (when available))
1292
+	 * @param boolean $_fetchPreviews = false (boolean/int) fetch part of the body of the messages requested (if integer the number is assumed to be the number of chars to be returned for preview; if set to true 300 chars are returned (when available))
1293 1293
 	 * @return array result as array(header=>array,total=>int,first=>int,last=>int)
1294 1294
 	 */
1295 1295
 	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
@@ -1866,6 +1866,7 @@  discard block
 block discarded – undo
1866 1866
 	 *
1867 1867
 	 * @param mixed _sort the integer sort order / or a valid and handeled SORTSTRING (right now: UID/ARRIVAL/INTERNALDATE (->ARRIVAL))
1868 1868
 	 * @param bool _reverse wether to add REVERSE to the Sort String or not
1869
+	 * @param integer $_sort
1869 1870
 	 * @return the sort sequence for horde search
1870 1871
 	 */
1871 1872
 	function _getSortString($_sort, $_reverse=false)
@@ -2375,7 +2376,7 @@  discard block
 block discarded – undo
2375 2376
 	 * @param string _parent the parent foldername
2376 2377
 	 * @param string _folderName the new foldername
2377 2378
 	 *
2378
-	 * @return mixed name of the newly created folder or false on error
2379
+	 * @return string name of the newly created folder or false on error
2379 2380
 	 * @throws Exception
2380 2381
 	 */
2381 2382
 	function renameFolder($_oldFolderName, $_parent, $_folderName)
@@ -3247,7 +3248,7 @@  discard block
 block discarded – undo
3247 3248
 	 * @param string $_mailbox
3248 3249
 	 * @param string $delimiter
3249 3250
 	 * @param string $prefix
3250
-	 * @param string $reclevel 0, counter to keep track of the current recursionlevel
3251
+	 * @param integer $reclevel 0, counter to keep track of the current recursionlevel
3251 3252
 	 * @return array of mailboxes
3252 3253
 	 */
3253 3254
 	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
@@ -3297,7 +3298,7 @@  discard block
 block discarded – undo
3297 3298
 	 * abstraction layer for getDraftFolder, getTemplateFolder, getTrashFolder and getSentFolder
3298 3299
 	 * @param string $_type the type to fetch (Drafts|Template|Trash|Sent)
3299 3300
 	 * @param boolean $_checkexistance trigger check for existance
3300
-	 * @param boolean& $created =null on return true: if folder was just created, false if not
3301
+	 * @param boolean $created =null on return true: if folder was just created, false if not
3301 3302
 	 * @return mixed string or false
3302 3303
 	 */
3303 3304
 	function _getSpecialUseFolder($_type, $_checkexistance=TRUE, &$created=null)
@@ -3429,7 +3430,7 @@  discard block
 block discarded – undo
3429 3430
 	/**
3430 3431
 	 * getTemplateFolder wrapper for _getSpecialUseFolder Type Template
3431 3432
 	 * @param boolean $_checkexistance trigger check for existance
3432
-	 * @return mixed string or false
3433
+	 * @return string string or false
3433 3434
 	 */
3434 3435
 	function getTemplateFolder($_checkexistance=TRUE)
3435 3436
 	{
@@ -3459,7 +3460,7 @@  discard block
 block discarded – undo
3459 3460
 	/**
3460 3461
 	 * getOutboxFolder wrapper for _getSpecialUseFolder Type Outbox
3461 3462
 	 * @param boolean $_checkexistance trigger check for existance
3462
-	 * @return mixed string or false
3463
+	 * @return string string or false
3463 3464
 	 */
3464 3465
 	function getOutboxFolder($_checkexistance=TRUE)
3465 3466
 	{
@@ -4298,7 +4299,7 @@  discard block
 block discarded – undo
4298 4299
 	/**
4299 4300
 	 * get part of the message, if its stucture is indicating its of multipart alternative style
4300 4301
 	 * a wrapper for multipartmixed
4301
-	 * @param string/int $_uid the messageuid,
4302
+	 * @param integer $_uid the messageuid,
4302 4303
 	 * @param Horde_Mime_Part $_structure structure for parsing
4303 4304
 	 * @param string $_htmlMode how to display a message, html, plain text, ...
4304 4305
 	 * @param boolean $_preserveSeen flag to preserve the seenflag by using body.peek
@@ -4948,6 +4949,9 @@  discard block
 block discarded – undo
4948 4949
 		return $message;
4949 4950
 	}
4950 4951
 
4952
+	/**
4953
+	 * @param integer $cols
4954
+	 */
4951 4955
 	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false)
4952 4956
 	{
4953 4957
 		$lines = explode("\n", $str);
@@ -5396,7 +5400,6 @@  discard block
 block discarded – undo
5396 5400
 	 * @param string $_partID = null
5397 5401
 	 * @param string $_folder = null
5398 5402
 	 * @param boolean $_preserveSeen = false flag to preserve the seenflag by using body.peek
5399
-	 * @param Horde_Imap_Client_Fetch_Query $fquery=null default query just structure
5400 5403
 	 * @return Horde_Mime_Part
5401 5404
 	 */
5402 5405
 	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
@@ -5987,6 +5990,7 @@  discard block
 block discarded – undo
5987 5990
 	 * @param preserveHTML flag to pass through to getdisplayableBody
5988 5991
 	 * @param addHeaderSection flag to be able to supress headersection
5989 5992
 	 * @param includeAttachments flag to be able to supress possible attachments
5993
+	 * @param Mail $mailClass
5990 5994
 	 * @return array/bool with 'mailaddress'=>$mailaddress,
5991 5995
 	 *				'subject'=>$subject,
5992 5996
 	 *				'message'=>$message,
@@ -6440,7 +6444,7 @@  discard block
 block discarded – undo
6440 6444
 	 *
6441 6445
 	 * @param Mailer $_mailObject instance of the Mailer Object to be used
6442 6446
 	 * @param string $_html2parse the html to parse and to be altered, if conditions meet
6443
-	 * @param $mail_bo mail bo object
6447
+	 * @param Mail $mail_bo mail bo object
6444 6448
 	 * @return void
6445 6449
 	 */
6446 6450
 	static function processURL2InlineImages(Mailer $_mailObject, &$_html2parse, $mail_bo)
@@ -6556,7 +6560,7 @@  discard block
 block discarded – undo
6556 6560
 	 * @param Storage\Merge Storage\Merge bo_merge object
6557 6561
 	 * @param string $document the full filename
6558 6562
 	 * @param array $SendAndMergeTocontacts array of contact ids
6559
-	 * @param string& $_folder (passed by reference) will set the folder used. must be set with a folder, but will hold modifications if
6563
+	 * @param string|null $_folder (passed by reference) will set the folder used. must be set with a folder, but will hold modifications if
6560 6564
 	 *					folder is modified
6561 6565
 	 * @param string& $importID ID for the imported message, used by attachments to identify them unambiguously
6562 6566
 	 * @return mixed array of messages with success and failed messages or exception
@@ -6800,7 +6804,7 @@  discard block
 block discarded – undo
6800 6804
 	/**
6801 6805
 	 * Parses a message/rfc mail from file to the mailobject
6802 6806
 	 *
6803
-	 * @param object $mailer instance of the SMTP Mailer Object
6807
+	 * @param Mailer $mailer instance of the SMTP Mailer Object
6804 6808
 	 * @param string $tmpFileName string that points/leads to the file to be imported
6805 6809
 	 * @throws Exception\NotFound if $fle is not found
6806 6810
 	 */
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -6730,14 +6730,14 @@
 block discarded – undo
6730 6730
 					{
6731 6731
 						if ($this->folderExists($_folder,true))
6732 6732
 						{
6733
-						    if($this->isSentFolder($_folder))
6733
+							if($this->isSentFolder($_folder))
6734 6734
 							{
6735
-						        $flags = '\\Seen';
6736
-						    } elseif($this->isDraftFolder($_folder)) {
6737
-						        $flags = '\\Draft';
6738
-						    } else {
6739
-						        $flags = '';
6740
-						    }
6735
+								$flags = '\\Seen';
6736
+							} elseif($this->isDraftFolder($_folder)) {
6737
+								$flags = '\\Draft';
6738
+							} else {
6739
+								$flags = '';
6740
+							}
6741 6741
 							$savefailed = false;
6742 6742
 							try
6743 6743
 							{
Please login to merge, or discard this patch.
Spacing   +1114 added lines, -1115 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 *
122 122
 	 * @array
123 123
 	 */
124
-	static $tidy_config = array('clean'=>false,'output-html'=>true,'join-classes'=>true,'join-styles'=>true,'show-body-only'=>"auto",'word-2000'=>true,'wrap'=>0);
124
+	static $tidy_config = array('clean'=>false, 'output-html'=>true, 'join-classes'=>true, 'join-styles'=>true, 'show-body-only'=>"auto", 'word-2000'=>true, 'wrap'=>0);
125 125
 
126 126
 	/**
127 127
 	 * static used to configure htmLawed, for use with emails
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	static $htmLawed_config = array('comment'=>1, //remove comments
132 132
 		'make_tag_strict' => 3, // 3 is a new own config value, to indicate that transformation is to be performed, but don't transform font as size transformation of numeric sizes to keywords alters the intended result too much
133 133
 		'keep_bad'=>2, //remove tags but keep element content (4 and 6 keep element content only if text (pcdata) is valid in parent element as per specs, this may lead to textloss if balance is switched on)
134
-		'balance'=>1,//turn off tag-balancing (config['balance']=>0). That will not introduce any security risk; only standards-compliant tag nesting check/filtering will be turned off (basic tag-balance will remain; i.e., there won't be any unclosed tag, etc., after filtering)
134
+		'balance'=>1, //turn off tag-balancing (config['balance']=>0). That will not introduce any security risk; only standards-compliant tag nesting check/filtering will be turned off (basic tag-balance will remain; i.e., there won't be any unclosed tag, etc., after filtering)
135 135
 		'direct_list_nest' => 1,
136
-		'allow_for_inline' => array('table','div','li','p'),//block elements allowed for nesting when only inline is allowed; Example span does not allow block elements as table; table is the only element tested so far
136
+		'allow_for_inline' => array('table', 'div', 'li', 'p'), //block elements allowed for nesting when only inline is allowed; Example span does not allow block elements as table; table is the only element tested so far
137 137
 		// tidy eats away even some wanted whitespace, so we switch it off;
138 138
 		// we used it for its compacting and beautifying capabilities, which resulted in better html for further processing
139 139
 		'tidy'=>0,
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @array
150 150
 	 */
151
-	static $aclShortCuts = array('' => array('label'=>'none','title'=>'The user has no rights whatsoever.'),
152
-		'lrs'		=> array('label'=>'readable','title'=>'Allows a user to read the contents of the mailbox.'),
153
-		'lprs'		=> array('label'=>'post','title'=>'Allows a user to read the mailbox and post to it through the delivery system by sending mail to the submission address of the mailbox.'),
154
-		'ilprs'		=> array('label'=>'append','title'=>'Allows a user to read the mailbox and append messages to it, either via IMAP or through the delivery system.'),
155
-		'cdilprsw'	=> array('label'=>'write','title'=>'Allows a user to read the maibox, post to it, append messages to it, and delete messages or the mailbox itself. The only right not given is the right to change the ACL of the mailbox.'),
156
-		'acdilprsw'	=> array('label'=>'all','title'=>'The user has all possible rights on the mailbox. This is usually granted to users only on the mailboxes they own.'),
157
-		'custom'	=> array('label'=>'custom','title'=>'User defined combination of rights for the ACL'),
151
+	static $aclShortCuts = array('' => array('label'=>'none', 'title'=>'The user has no rights whatsoever.'),
152
+		'lrs'		=> array('label'=>'readable', 'title'=>'Allows a user to read the contents of the mailbox.'),
153
+		'lprs'		=> array('label'=>'post', 'title'=>'Allows a user to read the mailbox and post to it through the delivery system by sending mail to the submission address of the mailbox.'),
154
+		'ilprs'		=> array('label'=>'append', 'title'=>'Allows a user to read the mailbox and append messages to it, either via IMAP or through the delivery system.'),
155
+		'cdilprsw'	=> array('label'=>'write', 'title'=>'Allows a user to read the maibox, post to it, append messages to it, and delete messages or the mailbox itself. The only right not given is the right to change the ACL of the mailbox.'),
156
+		'acdilprsw'	=> array('label'=>'all', 'title'=>'The user has all possible rights on the mailbox. This is usually granted to users only on the mailboxes they own.'),
157
+		'custom'	=> array('label'=>'custom', 'title'=>'User defined combination of rights for the ACL'),
158 158
 	);
159 159
 
160 160
 	/**
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * @param boolean $_reuseCache = null if null it is set to the value of $_restoreSession
196 196
 	 * @return Mail
197 197
 	 */
198
-	public static function getInstance($_restoreSession=true, &$_profileID=0, $_validate=true, $_oldImapServerObject=false, $_reuseCache=null)
198
+	public static function getInstance($_restoreSession = true, &$_profileID = 0, $_validate = true, $_oldImapServerObject = false, $_reuseCache = null)
199 199
 	{
200 200
 		//$_restoreSession=false;
201 201
 		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
@@ -205,13 +205,13 @@  discard block
 block discarded – undo
205 205
 		{
206 206
 			if (!is_object(self::$instances[$_profileID]))
207 207
 			{
208
-				self::$instances[$_profileID] = new Mail('utf-8',false,$_profileID,false,$_reuseCache);
208
+				self::$instances[$_profileID] = new Mail('utf-8', false, $_profileID, false, $_reuseCache);
209 209
 			}
210 210
 			self::$instances[$_profileID]->icServer = $_oldImapServerObject;
211
-			self::$instances[$_profileID]->accountid= $_oldImapServerObject->ImapServerId;
212
-			self::$instances[$_profileID]->profileID= $_oldImapServerObject->ImapServerId;
211
+			self::$instances[$_profileID]->accountid = $_oldImapServerObject->ImapServerId;
212
+			self::$instances[$_profileID]->profileID = $_oldImapServerObject->ImapServerId;
213 213
 			self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
214
-			self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
214
+			self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
215 215
 			return self::$instances[$_profileID];
216 216
 		}
217 217
 		if ($_profileID == 0)
@@ -224,14 +224,14 @@  discard block
 block discarded – undo
224 224
 			{
225 225
 				$profileID = Mail\Account::get_default_acc_id();
226 226
 			}
227
-			if ($profileID!=$_profileID) $_restoreSession==false;
228
-			$_profileID=$profileID;
227
+			if ($profileID != $_profileID) $_restoreSession == false;
228
+			$_profileID = $profileID;
229 229
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
230 230
 		}
231 231
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
232
-		if ($_oldImapServerObject===true)
232
+		if ($_oldImapServerObject === true)
233 233
 		{
234
-			return new Mail('utf-8',false,$_profileID,true,$_reuseCache);
234
+			return new Mail('utf-8', false, $_profileID, true, $_reuseCache);
235 235
 		}
236 236
 		if ($_profileID != 0 && $_validate)
237 237
 		{
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
 			//Cache::setSession('mail','activeProfileID',$_profileID);
252 252
 		}
253 253
 		//error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.' called from:'.function_backtrace());
254
-		if ($_profileID && (!isset(self::$instances[$_profileID]) || $_restoreSession===false))
254
+		if ($_profileID && (!isset(self::$instances[$_profileID]) || $_restoreSession === false))
255 255
 		{
256
-			self::$instances[$_profileID] = new Mail('utf-8',$_restoreSession,$_profileID,false,$_reuseCache);
256
+			self::$instances[$_profileID] = new Mail('utf-8', $_restoreSession, $_profileID, false, $_reuseCache);
257 257
 		}
258 258
 		else
259 259
 		{
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 				self::$instances[$_profileID]->ogServer = Mail\Account::read($_profileID)->smtpServer();
265 265
 				// TODO: merge mailprefs into userprefs, for easy treatment
266 266
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
267
-				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
267
+				self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
268 268
 			} catch (\Exception $e)
269 269
 			{
270 270
 				$newprofileID = Mail\Account::get_default_acc_id();
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 				error_log(__METHOD__.' ('.__LINE__.') '." Loading the Profile for ProfileID ".$_profileID.' failed for icServer; '.$e->getMessage().' Trigger new instance for Default-Profile '.$newprofileID.'. called from:'.function_backtrace());
273 273
 				if ($newprofileID)
274 274
 				{
275
-					self::$instances[$newprofileID] = new Mail('utf-8',false,$newprofileID,false,$_reuseCache);
275
+					self::$instances[$newprofileID] = new Mail('utf-8', false, $newprofileID, false, $_reuseCache);
276 276
 					$_profileID = $newprofileID;
277 277
 				}
278 278
 				else
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 					throw $e;
281 281
 				}
282 282
 			}
283
-			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
283
+			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate);
284 284
 		}
285 285
 		self::$instances[$_profileID]->profileID = $_profileID;
286 286
 		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new Horde_Idna;
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 * @param boolean $_testConnection = 0
297 297
 	 * @return mixed $_profileID or false on failed ConnectionTest
298 298
 	 */
299
-	public static function storeActiveProfileIDToPref($_icServerObject, $_profileID=0, $_testConnection=true)
299
+	public static function storeActiveProfileIDToPref($_icServerObject, $_profileID = 0, $_testConnection = true)
300 300
 	{
301 301
 		if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']) && !empty($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']))
302 302
 		{
@@ -317,12 +317,12 @@  discard block
 block discarded – undo
317 317
 		}
318 318
 		if ($oldProfileID != $_profileID)
319 319
 		{
320
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
321
-			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
320
+			if ($oldProfileID && $_profileID == 0) $_profileID = $oldProfileID;
321
+			$GLOBALS['egw']->preferences->add('mail', 'ActiveProfileID', $_profileID, 'user');
322 322
 			// save prefs
323 323
 			$GLOBALS['egw']->preferences->save_repository(true);
324 324
 			$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $_profileID;
325
-			Cache::setSession('mail','activeProfileID',$_profileID);
325
+			Cache::setSession('mail', 'activeProfileID', $_profileID);
326 326
 		}
327 327
 		return $_profileID;
328 328
 	}
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 	 * @param int $_acc_id = 0
338 338
 	 * @return int validated acc_id -> either acc_id given, or first valid one
339 339
 	 */
340
-	public static function validateProfileID($_acc_id=0)
340
+	public static function validateProfileID($_acc_id = 0)
341 341
 	{
342 342
 		if ($_acc_id)
343 343
 		{
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 		}
357 357
 		// no account specified or specified account not found or not valid
358 358
 		// --> search existing account for first valid one and return that
359
-		foreach(Mail\Account::search($only_current_user=true, 'acc_imap_host') as $acc_id => $imap_host)
359
+		foreach (Mail\Account::search($only_current_user = true, 'acc_imap_host') as $acc_id => $imap_host)
360 360
 		{
361 361
 			if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap())
362 362
 			{
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 	 * @param boolean $_oldImapServerObject = false
379 379
 	 * @param boolean $_reuseCache = null if null it is set to the value of $_restoreSession
380 380
 	 */
381
-	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
381
+	private function __construct($_displayCharset = 'utf-8', $_restoreSession = true, $_profileID = 0, $_oldImapServerObject = false, $_reuseCache = null)
382 382
 	{
383 383
 		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
384 384
 		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 			$firstMessage = $this->sessionData['previewMessage'];
399 399
 			$this->sessionData = array();
400 400
 		}
401
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
401
+		if (!$_reuseCache) $this->forcePrefReload($_profileID, !$_reuseCache);
402 402
 		try
403 403
 		{
404 404
 			$this->profileID = self::validateProfileID($_profileID);
@@ -409,14 +409,14 @@  discard block
 block discarded – undo
409 409
 		}
410 410
 		catch (\Exception $e)
411 411
 		{
412
-			throw new Exception(__METHOD__." failed to instanciate Mail for $_profileID / ".$this->profileID." with error:".$e->getMessage());;
412
+			throw new Exception(__METHOD__." failed to instanciate Mail for $_profileID / ".$this->profileID." with error:".$e->getMessage()); ;
413 413
 		}
414 414
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($acc->imapServer()));
415
-		$this->icServer = ($_oldImapServerObject?$acc->oldImapServer():$acc->imapServer());
415
+		$this->icServer = ($_oldImapServerObject ? $acc->oldImapServer() : $acc->imapServer());
416 416
 		$this->ogServer = $acc->smtpServer();
417 417
 		// TODO: merge mailprefs into userprefs, for easy treatment
418 418
 		$this->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
419
-		$this->htmlOptions  = $this->mailPreferences['htmlOptions'];
419
+		$this->htmlOptions = $this->mailPreferences['htmlOptions'];
420 420
 		if (isset($this->icServer->ImapServerId) && !empty($this->icServer->ImapServerId))
421 421
 		{
422 422
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 	public static function &forceEAProfileLoad($_profile_id)
435 435
 	{
436 436
 		self::unsetCachedObjects($_profile_id);
437
-		$mail = self::getInstance(false, $_profile_id,false);
437
+		$mail = self::getInstance(false, $_profile_id, false);
438 438
 		//_debug_array( $_profile_id);
439 439
 		$mail->icServer = Mail\Account::read($_profile_id)->imapServer();
440 440
 		$mail->ogServer = Mail\Account::read($_profile_id)->smtpServer();
@@ -446,11 +446,11 @@  discard block
 block discarded – undo
446 446
 	 * @param int $_profile_id
447 447
 	 * @param boolean $_resetFolderObjects
448 448
 	 */
449
-	public static function forcePrefReload($_profile_id=null,$_resetFolderObjects=true)
449
+	public static function forcePrefReload($_profile_id = null, $_resetFolderObjects = true)
450 450
 	{
451 451
 		// unset the mail_preferences session object, to force the reload/rebuild
452
-		Cache::setSession('mail','mail_preferences',serialize(array()));
453
-		Cache::setSession('emailadmin','session_data',serialize(array()));
452
+		Cache::setSession('mail', 'mail_preferences', serialize(array()));
453
+		Cache::setSession('emailadmin', 'session_data', serialize(array()));
454 454
 		if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id);
455 455
 	}
456 456
 
@@ -459,8 +459,8 @@  discard block
 block discarded – undo
459 459
 	 */
460 460
 	function restoreSessionData()
461 461
 	{
462
-		$this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
463
-		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
462
+		$this->sessionData = array(); //Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
463
+		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
464 464
 		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
465 465
 	}
466 466
 
@@ -470,10 +470,10 @@  discard block
 block discarded – undo
470 470
 	function saveSessionData()
471 471
 	{
472 472
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
473
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
473
+		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID] = $this->sessionData['mailbox'];
474 474
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
475 475
 		{
476
-			Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
476
+			Cache::setCache(Cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), self::$activeFolderCache, 60 * 60 * 10);
477 477
 		}
478 478
 	}
479 479
 
@@ -489,40 +489,40 @@  discard block
 block discarded – undo
489 489
 	 * @param int $_profileID = null default profile of user as returned by getUserDefaultProfileID
490 490
 	 * @return void
491 491
 	 */
492
-	static function unsetCachedObjects($_profileID=null)
492
+	static function unsetCachedObjects($_profileID = null)
493 493
 	{
494 494
 		if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id();
495 495
 		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
496 496
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
497
-		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
497
+		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID, 'tracker_') === false)))
498 498
 		{
499 499
 			self::resetConnectionErrorCache($_profileID);
500
-			$rawHeadersCache = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1);
500
+			$rawHeadersCache = Cache::getCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 1);
501 501
 			if (isset($rawHeadersCache[$_profileID]))
502 502
 			{
503 503
 				unset($rawHeadersCache[$_profileID]);
504
-				Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),$rawHeadersCache, $expiration=60*60*1);
504
+				Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), $rawHeadersCache, $expiration = 60 * 60 * 1);
505 505
 			}
506
-			$HierarchyDelimiterCache = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*24*5);
506
+			$HierarchyDelimiterCache = Cache::getCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 24 * 5);
507 507
 			if (isset($HierarchyDelimiterCache[$_profileID]))
508 508
 			{
509 509
 				unset($HierarchyDelimiterCache[$_profileID]);
510
-				Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),$HierarchyDelimiterCache, $expiration=60*60*24*5);
510
+				Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), $HierarchyDelimiterCache, $expiration = 60 * 60 * 24 * 5);
511 511
 			}
512 512
 			//reset folderObject cache, to trigger reload
513 513
 			self::resetFolderObjectCache($_profileID);
514 514
 			//reset counter of deleted messages per folder
515
-			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1);
515
+			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 1);
516 516
 			if (isset($eMailListContainsDeletedMessages[$_profileID]))
517 517
 			{
518 518
 				unset($eMailListContainsDeletedMessages[$_profileID]);
519
-				Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),$eMailListContainsDeletedMessages, $expiration=60*60*1);
519
+				Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), $eMailListContainsDeletedMessages, $expiration = 60 * 60 * 1);
520 520
 			}
521
-			$vacationCached = Cache::getCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*24*1);
521
+			$vacationCached = Cache::getCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 24 * 1);
522 522
 			if (isset($vacationCached[$_profileID]))
523 523
 			{
524 524
 				unset($vacationCached[$_profileID]);
525
-				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
525
+				Cache::setCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), $vacationCached, $expiration = 60 * 60 * 24 * 1);
526 526
 			}
527 527
 
528 528
 			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
@@ -530,17 +530,17 @@  discard block
 block discarded – undo
530 530
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
531 531
 		{
532 532
 			// called via hook
533
-			foreach($GLOBALS['egw']->accounts->search(array('type' => 'accounts','order' => 'account_lid')) as $account)
533
+			foreach ($GLOBALS['egw']->accounts->search(array('type' => 'accounts', 'order' => 'account_lid')) as $account)
534 534
 			{
535 535
 				//error_log(__METHOD__.__LINE__.array2string($account));
536 536
 				$account_id = $account['account_id'];
537 537
 				$_profileID = null;
538
-				self::resetConnectionErrorCache($_profileID,$account_id);
539
-				self::resetFolderObjectCache($_profileID,$account_id);
540
-				Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),array(), 60*60*1);
541
-				Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),array(), 60*60*24*5);
542
-				Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),array(), 60*60*1);
543
-				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),array(), 60*60*24*1);
538
+				self::resetConnectionErrorCache($_profileID, $account_id);
539
+				self::resetFolderObjectCache($_profileID, $account_id);
540
+				Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), array(), 60 * 60 * 1);
541
+				Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), array(), 60 * 60 * 24 * 5);
542
+				Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), array(), 60 * 60 * 1);
543
+				Cache::setCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), array(), 60 * 60 * 24 * 1);
544 544
 			}
545 545
 		}
546 546
 	}
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 	 * @param int $_ImapServerId the profileID to look for
552 552
 	 * @param int $account_id the egw account to look for
553 553
 	 */
554
-	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
554
+	static function resetConnectionErrorCache($_ImapServerId = null, $account_id = null)
555 555
 	{
556 556
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
557 557
 		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
@@ -569,19 +569,19 @@  discard block
 block discarded – undo
569 569
 		}
570 570
 		else
571 571
 		{
572
-			$isConError = Cache::getCache(Cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($account_id));
572
+			$isConError = Cache::getCache(Cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($account_id));
573 573
 			if (isset($isConError[$_ImapServerId]))
574 574
 			{
575 575
 				unset($isConError[$_ImapServerId]);
576 576
 			}
577
-			$waitOnFailure = Cache::getCache(Cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($account_id),null,array(),60*60*2);
577
+			$waitOnFailure = Cache::getCache(Cache::INSTANCE, 'email', 'ActiveSyncWaitOnFailure'.trim($account_id), null, array(), 60 * 60 * 2);
578 578
 			if (isset($waitOnFailure[$_ImapServerId]))
579 579
 			{
580 580
 				unset($waitOnFailure[$_ImapServerId]);
581 581
 			}
582 582
 		}
583
-		Cache::setCache(Cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($account_id),$isConError,60*15);
584
-		Cache::setCache(Cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($account_id),$waitOnFailure,60*60*2);
583
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($account_id), $isConError, 60 * 15);
584
+		Cache::setCache(Cache::INSTANCE, 'email', 'ActiveSyncWaitOnFailure'.trim($account_id), $waitOnFailure, 60 * 60 * 2);
585 585
 	}
586 586
 
587 587
 	/**
@@ -590,13 +590,13 @@  discard block
 block discarded – undo
590 590
 	 * @param int $_ImapServerId the profileID to look for
591 591
 	 * @param int $account_id the egw account to look for
592 592
 	 */
593
-	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
593
+	static function resetFolderObjectCache($_ImapServerId = null, $account_id = null)
594 594
 	{
595 595
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
596 596
 		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
597 597
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
598 598
 		// or treat it as not given. we try that path
599
-		if (is_null($_ImapServerId)||is_array($_ImapServerId))
599
+		if (is_null($_ImapServerId) || is_array($_ImapServerId))
600 600
 		{
601 601
 			$folders2return = array();
602 602
 			$folderInfo = array();
@@ -605,12 +605,12 @@  discard block
 block discarded – undo
605 605
 		}
606 606
 		else
607 607
 		{
608
-			$folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($account_id),null,array(),60*60*1);
608
+			$folders2return = Cache::getCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($account_id), null, array(), 60 * 60 * 1);
609 609
 			if (!empty($folders2return) && isset($folders2return[$_ImapServerId]))
610 610
 			{
611 611
 				unset($folders2return[$_ImapServerId]);
612 612
 			}
613
-			$folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),null,array(),60*60*5);
613
+			$folderInfo = Cache::getCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($account_id), null, array(), 60 * 60 * 5);
614 614
 			if (!empty($folderInfo) && isset($folderInfo[$_ImapServerId]))
615 615
 			{
616 616
 				unset($folderInfo[$_ImapServerId]);
@@ -622,23 +622,23 @@  discard block
 block discarded – undo
622 622
 				unset($lastFolderUsedForMove[$_ImapServerId]);
623 623
 			}
624 624
 			*/
625
-			$folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),null,array(),60*60*1);
625
+			$folderBasicInfo = Cache::getCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($account_id), null, array(), 60 * 60 * 1);
626 626
 			if (!empty($folderBasicInfo) && isset($folderBasicInfo[$_ImapServerId]))
627 627
 			{
628 628
 				unset($folderBasicInfo[$_ImapServerId]);
629 629
 			}
630
-			$_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($account_id),null,array(),60*60*12);
630
+			$_specialUseFolders = Cache::getCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($account_id), null, array(), 60 * 60 * 12);
631 631
 			if (!empty($_specialUseFolders) && isset($_specialUseFolders[$_ImapServerId]))
632 632
 			{
633 633
 				unset($_specialUseFolders[$_ImapServerId]);
634
-				self::$specialUseFolders=null;
634
+				self::$specialUseFolders = null;
635 635
 			}
636 636
 		}
637
-		Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($account_id),$folders2return, 60*60*1);
638
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),$folderInfo,60*60*5);
637
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($account_id), $folders2return, 60 * 60 * 1);
638
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($account_id), $folderInfo, 60 * 60 * 5);
639 639
 		//Cache::setCache(Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($account_id),$lastFolderUsedForMove,$expiration=60*60*1);
640
-		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),$folderBasicInfo,60*60*1);
641
-		Cache::setCache(Cache::INSTANCE,'email','specialUseFolders'.trim($account_id),$_specialUseFolders,60*60*12);
640
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($account_id), $folderBasicInfo, 60 * 60 * 1);
641
+		Cache::setCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($account_id), $_specialUseFolders, 60 * 60 * 12);
642 642
 	}
643 643
 
644 644
 	/**
@@ -659,15 +659,15 @@  discard block
 block discarded – undo
659 659
 	 * @param string $_profileID the ID of the mailaccount to check for identities, if null current mail-account is used
660 660
 	 * @return array - array(email=>realname)
661 661
 	 */
662
-	function getUserEMailAddresses($_profileID=null)
662
+	function getUserEMailAddresses($_profileID = null)
663 663
 	{
664
-		$acc = Mail\Account::read((!empty($_profileID)?$_profileID:$this->profileID));
664
+		$acc = Mail\Account::read((!empty($_profileID) ? $_profileID : $this->profileID));
665 665
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($acc));
666 666
 		$identities = Mail\Account::identities($acc);
667 667
 
668 668
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
669 669
 
670
-		foreach($identities as $ik => $ident) {
670
+		foreach ($identities as $ik => $ident) {
671 671
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
672 672
 			$identity = Mail\Account::read_identity($ik);
673 673
 			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
@@ -682,19 +682,19 @@  discard block
 block discarded – undo
682 682
 	 * @param boolean $resolve_placeholders wether or not resolve possible placeholders in identities
683 683
 	 * @return array - array(email=>realname)
684 684
 	 */
685
-	static function getAllIdentities($_accountToSearch=null,$resolve_placeholders=false)
685
+	static function getAllIdentities($_accountToSearch = null, $resolve_placeholders = false)
686 686
 	{
687 687
 		$userEMailAdresses = array();
688
-		foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
688
+		foreach (Mail\Account::search($only_current_user = ($_accountToSearch ? $_accountToSearch : true), $just_name = true) as $acc_id => $identity_name)
689 689
 		{
690
-			$acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
691
-			if (!$resolve_placeholders) $userEMailAdresses[$acc['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$acc['ident_id'],'ident_email'=>$acc['ident_email'],'ident_org'=>$acc['ident_org'],'ident_realname'=>$acc['ident_realname'],'ident_signature'=>$acc['ident_signature'],'ident_name'=>$acc['ident_name']);
690
+			$acc = Mail\Account::read($acc_id, ($_accountToSearch ? $_accountToSearch : null));
691
+			if (!$resolve_placeholders) $userEMailAdresses[$acc['ident_id']] = array('acc_id'=>$acc_id, 'ident_id'=>$acc['ident_id'], 'ident_email'=>$acc['ident_email'], 'ident_org'=>$acc['ident_org'], 'ident_realname'=>$acc['ident_realname'], 'ident_signature'=>$acc['ident_signature'], 'ident_name'=>$acc['ident_name']);
692 692
 
693
-			foreach(Mail\Account::identities($acc) as $ik => $ident) {
693
+			foreach (Mail\Account::identities($acc) as $ik => $ident) {
694 694
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
695
-				$identity = Mail\Account::read_identity($ik,$resolve_placeholders);
695
+				$identity = Mail\Account::read_identity($ik, $resolve_placeholders);
696 696
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
697
-				if (!isset($userEMailAdresses[$identity['ident_id']])) $userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$identity['ident_id'],'ident_email'=>$identity['ident_email'],'ident_org'=>$identity['ident_org'],'ident_realname'=>$identity['ident_realname'],'ident_signature'=>$identity['ident_signature'],'ident_name'=>$identity['ident_name']);
697
+				if (!isset($userEMailAdresses[$identity['ident_id']])) $userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$acc_id, 'ident_id'=>$identity['ident_id'], 'ident_email'=>$identity['ident_email'], 'ident_org'=>$identity['ident_org'], 'ident_realname'=>$identity['ident_realname'], 'ident_signature'=>$identity['ident_signature'], 'ident_name'=>$identity['ident_name']);
698 698
 			}
699 699
 		}
700 700
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -714,9 +714,9 @@  discard block
 block discarded – undo
714 714
 			$account = Mail\Account::read($account);
715 715
 		}
716 716
 		$userEMailAdresses = array();
717
-		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) {
717
+		foreach (Mail\Account::identities($account, true, 'params') as $ik => $ident) {
718 718
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
719
-			$identity = Mail\Account::read_identity($ik,true,null,$account);
719
+			$identity = Mail\Account::read_identity($ik, true, null, $account);
720 720
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
721 721
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
722 722
 			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
@@ -743,9 +743,9 @@  discard block
 block discarded – undo
743 743
 	function getDefaultIdentity()
744 744
 	{
745 745
 		// retrieve the signature accociated with the identity
746
-		$id = $this->getIdentitiesWithAccounts($_accountData=array());
747
-		foreach(Mail\Account::identities($_accountData[$this->profileID] ?
748
-			$this->profileID : $_accountData[$id],false,'ident_id') as $accountData)
746
+		$id = $this->getIdentitiesWithAccounts($_accountData = array());
747
+		foreach (Mail\Account::identities($_accountData[$this->profileID] ?
748
+			$this->profileID : $_accountData[$id], false, 'ident_id') as $accountData)
749 749
 		{
750 750
 			return $accountData;
751 751
 		}
@@ -761,13 +761,13 @@  discard block
 block discarded – undo
761 761
 	{
762 762
 		// account select box
763 763
 		$selectedID = $this->profileID;
764
-		$allAccountData = Mail\Account::search($only_current_user=true, false, null);
764
+		$allAccountData = Mail\Account::search($only_current_user = true, false, null);
765 765
 		if ($allAccountData) {
766
-			$rememberFirst=$selectedFound=null;
766
+			$rememberFirst = $selectedFound = null;
767 767
 			foreach ($allAccountData as $tmpkey => $icServers)
768 768
 			{
769 769
 				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
770
-				if ($tmpkey == $selectedID) $selectedFound=true;
770
+				if ($tmpkey == $selectedID) $selectedFound = true;
771 771
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
772 772
 				$host = $icServers->acc_imap_host;
773 773
 				if (empty($host)) continue;
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
776 776
 			}
777 777
 		}
778
-		return ($selectedFound?$selectedID:$rememberFirst);
778
+		return ($selectedFound ? $selectedID : $rememberFirst);
779 779
 	}
780 780
 
781 781
 	/**
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 	 * @var boolean $fullString full or false=NamePart only is returned
786 786
 	 * @return string - constructed of identity object data as defined in mailConfig
787 787
 	 */
788
-	static function generateIdentityString($identity, $fullString=true)
788
+	static function generateIdentityString($identity, $fullString = true)
789 789
 	{
790 790
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($identity));
791 791
 		//if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
@@ -796,16 +796,16 @@  discard block
 block discarded – undo
796 796
 		{
797 797
 			case 'email';
798 798
 				//$retData = str_replace('@',' ',$identity->emailAddress).($fullString===true?' <'.$identity->emailAddress.'>':'');
799
-				$retData = $identity['ident_email'].($fullString===true?' <'.$identity['ident_email'].'>':'');
799
+				$retData = $identity['ident_email'].($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
800 800
 				break;
801 801
 			case 'nameNemail';
802
-				$retData = (!empty($identity['ident_realname'])?$identity['ident_realname']:substr_replace($identity['ident_email'],'',strpos($identity['ident_email'],'@'))).($fullString===true?' <'.$identity['ident_email'].'>':'');
802
+				$retData = (!empty($identity['ident_realname']) ? $identity['ident_realname'] : substr_replace($identity['ident_email'], '', strpos($identity['ident_email'], '@'))).($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
803 803
 				break;
804 804
 			case 'orgNemail';
805
-				$retData = (!empty($identity['ident_org'])?$identity['ident_org']:substr_replace($identity['ident_email'],'',0,strpos($identity['ident_email'],'@')+1)).($fullString===true?' <'.$identity['ident_email'].'>':'');
805
+				$retData = (!empty($identity['ident_org']) ? $identity['ident_org'] : substr_replace($identity['ident_email'], '', 0, strpos($identity['ident_email'], '@') + 1)).($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
806 806
 				break;
807 807
 			default:
808
-				$retData = $identity['ident_realname'].(!empty($identity['ident_org'])?' '.$identity['ident_org']:'').($fullString===true?' <'.$identity['ident_email'].'>':'');
808
+				$retData = $identity['ident_realname'].(!empty($identity['ident_org']) ? ' '.$identity['ident_org'] : '').($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
809 809
 		}
810 810
 		return $retData;
811 811
 	}
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
 	 */
831 831
 	function reopen($_foldername)
832 832
 	{
833
-		if (self::$debugTimes) $starttime = microtime (true);
833
+		if (self::$debugTimes) $starttime = microtime(true);
834 834
 
835 835
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
836 836
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
 			}
846 846
 			$folderOpened = $_foldername;
847 847
 		//}
848
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
848
+		if (self::$debugTimes) self::logRunTimes($starttime, null, 'Folder:'.$_foldername, __METHOD__.' ('.__LINE__.') ');
849 849
 	}
850 850
 
851 851
 
@@ -856,15 +856,15 @@  discard block
 block discarded – undo
856 856
 	 * @throws Horde_Imap_Client_Exception on connection error or authentication failure
857 857
 	 * @throws InvalidArgumentException on missing credentials
858 858
 	 */
859
-	function openConnection($_icServerID=0)
859
+	function openConnection($_icServerID = 0)
860 860
 	{
861 861
 		//error_log( "-------------------------->open connection ".function_backtrace());
862 862
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
863
-		if (self::$debugTimes) $starttime = microtime (true);
864
-		$mailbox=null;
863
+		if (self::$debugTimes) $starttime = microtime(true);
864
+		$mailbox = null;
865 865
 		try
866 866
 		{
867
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
867
+			if (isset($this->sessionData['mailbox']) && $this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
868 868
 			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
869 869
 /*
870 870
 			if (isset(Mail\Imap::$supports_keywords[$_icServerID]))
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage());
892 892
 			throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage());
893 893
 		}
894
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
894
+		if (self::$debugTimes) self::logRunTimes($starttime, null, 'ProfileID:'.$_icServerID, __METHOD__.' ('.__LINE__.') ');
895 895
 	}
896 896
 
897 897
 	/**
@@ -905,13 +905,13 @@  discard block
 block discarded – undo
905 905
 		static $quota;
906 906
 		if (isset($quota)) return $quota;
907 907
 		$this->icServer->getCurrentMailbox();
908
-		if(!$this->icServer->hasCapability('QUOTA')) {
908
+		if (!$this->icServer->hasCapability('QUOTA')) {
909 909
 			$quota = false;
910 910
 			return false;
911 911
 		}
912 912
 		$quota = $this->icServer->getStorageQuotaRoot('INBOX');
913 913
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
914
-		if(is_array($quota)) {
914
+		if (is_array($quota)) {
915 915
 			$quota = array(
916 916
 				'usage'	=> $quota['USED'],
917 917
 				'limit'	=> $quota['QMAX'],
@@ -929,10 +929,10 @@  discard block
 block discarded – undo
929 929
 	 *
930 930
 	 * @return int - timeout (either set or default 20/10)
931 931
 	 */
932
-	static function getTimeOut($_use='IMAP')
932
+	static function getTimeOut($_use = 'IMAP')
933 933
 	{
934 934
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
935
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
935
+		if (empty($timeout)) $timeout = ($_use == 'SIEVE' ? 10 : 20); // this is the default value
936 936
 		return $timeout;
937 937
 	}
938 938
 
@@ -953,18 +953,18 @@  discard block
 block discarded – undo
953 953
 		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
954 954
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
955 955
 		if (is_array($nameSpace)) {
956
-			foreach($nameSpace as $type => $singleNameSpaceArray)
956
+			foreach ($nameSpace as $type => $singleNameSpaceArray)
957 957
 			{
958 958
 				foreach ($singleNameSpaceArray as $singleNameSpace)
959 959
 				{
960 960
 					$_foldersNameSpace = array();
961
-					if($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail')||$this->folderExists('INBOX')))
961
+					if ($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail') || $this->folderExists('INBOX')))
962 962
 					{
963 963
 						$_foldersNameSpace['prefix_present'] = 'forced';
964 964
 						// uw-imap server with mailbox prefix or dovecot maybe
965
-						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail')?'Mail':(!empty($singleNameSpace['name'])?$singleNameSpace['name']:''));
965
+						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail') ? 'Mail' : (!empty($singleNameSpace['name']) ? $singleNameSpace['name'] : ''));
966 966
 					}
967
-					elseif($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
967
+					elseif ($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
968 968
 					{
969 969
 						$_foldersNameSpace['prefix_present'] = 'forced';
970 970
 						// uw-imap server with mailbox prefix or dovecot maybe
@@ -973,9 +973,9 @@  discard block
 block discarded – undo
973 973
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
974 974
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
975 975
 					}
976
-					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter']?$singleNameSpace['delimiter']:$delimiter);
976
+					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter'] ? $singleNameSpace['delimiter'] : $delimiter);
977 977
 					$_foldersNameSpace['type'] = $type;
978
-					$foldersNameSpace[] =$_foldersNameSpace;
978
+					$foldersNameSpace[] = $_foldersNameSpace;
979 979
 				}
980 980
 				//echo "############## $type->".print_r($foldersNameSpace[$type],true)." ###################<br>";
981 981
 			}
@@ -993,10 +993,10 @@  discard block
 block discarded – undo
993 993
 	 */
994 994
 	function getFolderPrefixFromNamespace($nameSpace, $folderName)
995 995
 	{
996
-		foreach($nameSpace as &$singleNameSpace)
996
+		foreach ($nameSpace as &$singleNameSpace)
997 997
 		{
998 998
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
999
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
999
+			if (substr($folderName, 0, strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1000 1000
 		}
1001 1001
 		return "";
1002 1002
 	}
@@ -1007,12 +1007,12 @@  discard block
 block discarded – undo
1007 1007
 	 * @var boolean $_useCache
1008 1008
 	 * @return string the hierarchyDelimiter
1009 1009
 	 */
1010
-	function getHierarchyDelimiter($_useCache=true)
1010
+	function getHierarchyDelimiter($_useCache = true)
1011 1011
 	{
1012 1012
 		static $HierarchyDelimiter = null;
1013
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1014
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1015
-		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1013
+		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 24 * 5);
1014
+		if ($_useCache === false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1015
+		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId]) && !empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1016 1016
 		{
1017 1017
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
1018 1018
 		}
@@ -1022,12 +1022,12 @@  discard block
 block discarded – undo
1022 1022
 			$this->icServer->getCurrentMailbox();
1023 1023
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = $this->icServer->getDelimiter();
1024 1024
 		}
1025
-		catch(\Exception $e)
1025
+		catch (\Exception $e)
1026 1026
 		{
1027 1027
 			unset($e);
1028 1028
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = '/';
1029 1029
 		}
1030
-		Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),$HierarchyDelimiter, 60*60*24*5);
1030
+		Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']), $HierarchyDelimiter, 60 * 60 * 24 * 5);
1031 1031
 		return $HierarchyDelimiter[$this->icServer->ImapServerId];
1032 1032
 	}
1033 1033
 
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
 	{
1041 1041
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1042 1042
 		static $_specialUseFolders = null;
1043
-		if (is_null($_specialUseFolders)||empty($_specialUseFolders)) $_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1043
+		if (is_null($_specialUseFolders) || empty($_specialUseFolders)) $_specialUseFolders = Cache::getCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 24 * 5);
1044 1044
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1045 1045
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1046 1046
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
@@ -1048,20 +1048,20 @@  discard block
 block discarded – undo
1048 1048
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1049 1049
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1050 1050
 			return $_specialUseFolders[$this->icServer->ImapServerId];
1051
-		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1051
+		$_specialUseFolders[$this->icServer->ImapServerId] = array();
1052 1052
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1053
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
1053
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash] = 'Trash';
1054 1054
 		//if (!empty($this->icServer->acc_folder_draft) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft]))
1055
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft]='Drafts';
1055
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft] = 'Drafts';
1056 1056
 		//if (!empty($this->icServer->acc_folder_sent) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent]))
1057
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent]='Sent';
1057
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent] = 'Sent';
1058 1058
 		//if (!empty($this->icServer->acc_folder_template) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template]))
1059
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template]='Templates';
1060
-		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_junk]='Junk';
1061
-		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_archive]='Archive';
1059
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template] = 'Templates';
1060
+		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_junk] = 'Junk';
1061
+		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_archive] = 'Archive';
1062 1062
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_specialUseFolders));//.'<->'.array2string($this->icServer));
1063 1063
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1064
-		Cache::setCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$_specialUseFolders, 60*60*24*5);
1064
+		Cache::setCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']), $_specialUseFolders, 60 * 60 * 24 * 5);
1065 1065
 		return $_specialUseFolders[$this->icServer->ImapServerId];
1066 1066
 	}
1067 1067
 
@@ -1075,8 +1075,8 @@  discard block
 block discarded – undo
1075 1075
 	function folderIsSelectable($folderToSelect)
1076 1076
 	{
1077 1077
 		$retval = true;
1078
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1079
-			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1078
+		if ($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect, false, true))) {
1079
+			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']), 'noselect') !== false)
1080 1080
 			{
1081 1081
 				$retval = false;
1082 1082
 			}
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
 	 *
1097 1097
 	 * @throws Exception
1098 1098
 	 */
1099
-	function _getStatus($folderName,$ignoreStatusCache=false)
1099
+	function _getStatus($folderName, $ignoreStatusCache = false)
1100 1100
 	{
1101 1101
 		static $folderStatus = null;
1102 1102
 		if (!$ignoreStatusCache && isset($folderStatus[$this->icServer->ImapServerId][$folderName]))
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
 		}
1107 1107
 		try
1108 1108
 		{
1109
-			$folderStatus[$this->icServer->ImapServerId][$folderName] = $this->icServer->getStatus($folderName,$ignoreStatusCache);
1109
+			$folderStatus[$this->icServer->ImapServerId][$folderName] = $this->icServer->getStatus($folderName, $ignoreStatusCache);
1110 1110
 		}
1111 1111
 		catch (\Exception $e)
1112 1112
 		{
@@ -1126,7 +1126,7 @@  discard block
 block discarded – undo
1126 1126
 	 * @param fetchSubscribedInfo bool fetch Subscribed Info on folder
1127 1127
 	 * @return array
1128 1128
 	 */
1129
-	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1129
+	function getFolderStatus($_folderName, $ignoreStatusCache = false, $basicInfoOnly = false, $fetchSubscribedInfo = true)
1130 1130
 	{
1131 1131
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1132 1132
 		if (!is_string($_folderName) || empty($_folderName)) // something is wrong. Do not proceed
@@ -1139,7 +1139,7 @@  discard block
 block discarded – undo
1139 1139
 		{
1140 1140
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1141 1141
 		}
1142
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1142
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache == false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1143 1143
 		$retValue = array();
1144 1144
 		$retValue['subscribed'] = false;
1145 1145
 /*
@@ -1157,28 +1157,28 @@  discard block
 block discarded – undo
1157 1157
 			if (is_array($ret))
1158 1158
 			{
1159 1159
 				$retkeys = array_keys($ret);
1160
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1160
+				if ($retkeys[0] == $_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1161 1161
 			}
1162 1162
 			else
1163 1163
 			{
1164
-				$folderInfoCache[$_folderName]=false;
1164
+				$folderInfoCache[$_folderName] = false;
1165 1165
 			}
1166 1166
 		}
1167 1167
 		$folderInfo = $folderInfoCache[$_folderName];
1168 1168
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1169
-		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) {
1169
+		if ($ignoreStatusCache || !$folderInfo || !is_array($folderInfo)) {
1170 1170
 			try
1171 1171
 			{
1172
-				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
1172
+				$folderInfo = $this->_getStatus($_folderName, $ignoreStatusCache);
1173 1173
 			}
1174 1174
 			catch (\Exception $e)
1175 1175
 			{
1176
-				$folderInfo=null;
1176
+				$folderInfo = null;
1177 1177
 			}
1178 1178
 			if (!is_array($folderInfo))
1179 1179
 			{
1180 1180
 				// no folder info, but there is a status returned for the folder: something is wrong, try to cope with it
1181
-				$folderInfo = is_array($folderInfo)?$folderInfo:array('HIERACHY_DELIMITER'=>$this->getHierarchyDelimiter(),
1181
+				$folderInfo = is_array($folderInfo) ? $folderInfo : array('HIERACHY_DELIMITER'=>$this->getHierarchyDelimiter(),
1182 1182
 					'ATTRIBUTES' => '');
1183 1183
 				if (!isset($folderInfo['HIERACHY_DELIMITER']) || empty($folderInfo['HIERACHY_DELIMITER']) || (isset($folderInfo['delimiter']) && empty($folderInfo['delimiter'])))
1184 1184
 				{
@@ -1190,24 +1190,24 @@  discard block
 block discarded – undo
1190 1190
 		#if(!is_array($folderInfo)) {
1191 1191
 		#	return false;
1192 1192
 		#}
1193
-		$retValue['delimiter']		= (isset($folderInfo['HIERACHY_DELIMITER']) && $folderInfo['HIERACHY_DELIMITER']?$folderInfo['HIERACHY_DELIMITER']:$folderInfo['delimiter']);
1194
-		$retValue['attributes']		= (isset($folderInfo['ATTRIBUTES']) && $folderInfo['ATTRIBUTES']?$folderInfo['ATTRIBUTES']:$folderInfo['attributes']);
1195
-		$shortNameParts			= explode($retValue['delimiter'], $_folderName);
1193
+		$retValue['delimiter']		= (isset($folderInfo['HIERACHY_DELIMITER']) && $folderInfo['HIERACHY_DELIMITER'] ? $folderInfo['HIERACHY_DELIMITER'] : $folderInfo['delimiter']);
1194
+		$retValue['attributes']		= (isset($folderInfo['ATTRIBUTES']) && $folderInfo['ATTRIBUTES'] ? $folderInfo['ATTRIBUTES'] : $folderInfo['attributes']);
1195
+		$shortNameParts = explode($retValue['delimiter'], $_folderName);
1196 1196
 		$retValue['shortName']		= array_pop($shortNameParts);
1197 1197
 		$retValue['displayName']	= $_folderName;
1198
-		$retValue['shortDisplayName']	= $retValue['shortName'];
1199
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1200
-			$retValue['displayName']	= lang('INBOX');
1201
-			$retValue['shortDisplayName']	= lang('INBOX');
1198
+		$retValue['shortDisplayName'] = $retValue['shortName'];
1199
+		if (strtoupper($retValue['shortName']) == 'INBOX') {
1200
+			$retValue['displayName'] = lang('INBOX');
1201
+			$retValue['shortDisplayName'] = lang('INBOX');
1202 1202
 		}
1203 1203
 		// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
1204
-		elseif (in_array($retValue['shortName'],self::$autoFolders))
1204
+		elseif (in_array($retValue['shortName'], self::$autoFolders))
1205 1205
 		{
1206 1206
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1207 1207
 		}
1208
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1208
+		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName] = $retValue;
1209 1209
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1210
-		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1210
+		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']), 'noselect') !== false))
1211 1211
 		{
1212 1212
 			return $retValue;
1213 1213
 		}
@@ -1220,12 +1220,12 @@  discard block
 block discarded – undo
1220 1220
 		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1221 1221
 		if (!empty($nameSpace[$this->profileID]))
1222 1222
 		{
1223
-			$nsNoPersonal=array();
1224
-			foreach($nameSpace[$this->profileID] as &$ns)
1223
+			$nsNoPersonal = array();
1224
+			foreach ($nameSpace[$this->profileID] as &$ns)
1225 1225
 			{
1226
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1226
+				if ($ns['type'] != 'personal') $nsNoPersonal[] = $ns;
1227 1227
 			}
1228
-			$nameSpace[$this->profileID]=$nsNoPersonal;
1228
+			$nameSpace[$this->profileID] = $nsNoPersonal;
1229 1229
 		}
1230 1230
 		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1231 1231
 
@@ -1234,32 +1234,32 @@  discard block
 block discarded – undo
1234 1234
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1235 1235
 		}
1236 1236
 
1237
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1237
+		if ($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName, $subscribedFolders[$this->profileID])) {
1238 1238
 			$retValue['subscribed'] = true;
1239 1239
 		}
1240 1240
 
1241 1241
 		try
1242 1242
 		{
1243 1243
 			//$folderStatus = $this->_getStatus($_folderName,$ignoreStatusCache);
1244
-			$folderStatus = $this->getMailBoxCounters($_folderName,false);
1245
-			$retValue['messages']		= $folderStatus['MESSAGES'];
1244
+			$folderStatus = $this->getMailBoxCounters($_folderName, false);
1245
+			$retValue['messages'] = $folderStatus['MESSAGES'];
1246 1246
 			$retValue['recent']		= $folderStatus['RECENT'];
1247
-			$retValue['uidnext']		= $folderStatus['UIDNEXT'];
1248
-			$retValue['uidvalidity']	= $folderStatus['UIDVALIDITY'];
1247
+			$retValue['uidnext'] = $folderStatus['UIDNEXT'];
1248
+			$retValue['uidvalidity'] = $folderStatus['UIDVALIDITY'];
1249 1249
 			$retValue['unseen']		= $folderStatus['UNSEEN'];
1250 1250
 			if (//$retValue['unseen']==0 &&
1251 1251
 				(isset($this->mailPreferences['trustServersUnseenInfo']) && // some servers dont serve the UNSEEN information
1252
-				$this->mailPreferences['trustServersUnseenInfo']==false) ||
1252
+				$this->mailPreferences['trustServersUnseenInfo'] == false) ||
1253 1253
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1254
-				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1255
-				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1254
+				$this->mailPreferences['trustServersUnseenInfo'] == 2 &&
1255
+				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName, $prefix[$this->profileID][$_folderName]) !== false)
1256 1256
 			)
1257 1257
 			{
1258 1258
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1259 1259
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1260 1260
 				try
1261 1261
 				{
1262
-					$sortResult = $this->getSortedList($_folderName, $_sort=0, $_reverse=1, array('status'=>array('UNSEEN','UNDELETED')),$byUid=true,false);
1262
+					$sortResult = $this->getSortedList($_folderName, $_sort = 0, $_reverse = 1, array('status'=>array('UNSEEN', 'UNDELETED')), $byUid = true, false);
1263 1263
 					$retValue['unseen'] = $sortResult['count'];
1264 1264
 				}
1265 1265
 				catch (\Exception $ee)
@@ -1270,7 +1270,7 @@  discard block
 block discarded – undo
1270 1270
 		}
1271 1271
 		catch (\Exception $e)
1272 1272
 		{
1273
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1273
+			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(), true));
1274 1274
 		}
1275 1275
 
1276 1276
 		return $retValue;
@@ -1292,7 +1292,7 @@  discard block
 block discarded – undo
1292 1292
 	 * @param mixed $_fetchPreviews = false (boolean/int) fetch part of the body of the messages requested (if integer the number is assumed to be the number of chars to be returned for preview; if set to true 300 chars are returned (when available))
1293 1293
 	 * @return array result as array(header=>array,total=>int,first=>int,last=>int)
1294 1294
 	 */
1295
-	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1295
+	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly = null, $_cacheResult = true, $_fetchPreviews = false)
1296 1296
 	{
1297 1297
 		//self::$debug=true;
1298 1298
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
@@ -1305,7 +1305,7 @@  discard block
 block discarded – undo
1305 1305
 		$rByUid = true; // try searching by uid. this var will be passed by reference to getSortedList, and may be set to false, if UID retrieval fails
1306 1306
 		#print "<pre>";
1307 1307
 		#$this->icServer->setDebug(true);
1308
-		$total=0;
1308
+		$total = 0;
1309 1309
 		if ($_thisUIDOnly === null)
1310 1310
 		{
1311 1311
 			if (($_startMessage || $_numberOfMessages) && !isset($_filter['range']))
@@ -1318,24 +1318,24 @@  discard block
 block discarded – undo
1318 1318
 				//$_filter['range'] ="$_startMessage:*";
1319 1319
 			}
1320 1320
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1321
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1321
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1322 1322
 			//see this example below for a 12 week datefilter (since)
1323 1323
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1324 1324
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1325 1325
 			$sortResult = $_sortResult['match']->ids;
1326 1326
 			//$modseq = $_sortResult['modseq'];
1327 1327
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1328
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1328
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly), __METHOD__.' ('.__LINE__.') ');
1329 1329
 
1330 1330
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1331 1331
 			#$this->icServer->setDebug(false);
1332 1332
 			#print "</pre>";
1333 1333
 			// nothing found
1334
-			if(!is_array($sortResult) || empty($sortResult)) {
1334
+			if (!is_array($sortResult) || empty($sortResult)) {
1335 1335
 				$retValue = array();
1336 1336
 				$retValue['info']['total']	= 0;
1337 1337
 				$retValue['info']['first']	= 0;
1338
-				$retValue['info']['last']	= 0;
1338
+				$retValue['info']['last'] = 0;
1339 1339
 				return $retValue;
1340 1340
 			}
1341 1341
 
@@ -1343,54 +1343,54 @@  discard block
 block discarded – undo
1343 1343
 			#_debug_array($sortResult);
1344 1344
 			#_debug_array(array_slice($sortResult, -5, -2));
1345 1345
 			//error_log("REVERSE: $reverse");
1346
-			if($reverse === true) {
1347
-				if  ($_startMessage<=$total)
1346
+			if ($reverse === true) {
1347
+				if ($_startMessage <= $total)
1348 1348
 				{
1349
-					$startMessage = $_startMessage-1;
1349
+					$startMessage = $_startMessage - 1;
1350 1350
 				}
1351 1351
 				else
1352 1352
 				{
1353 1353
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1354
-					if ($_startMessage+$_numberOfMessages>$total)
1354
+					if ($_startMessage + $_numberOfMessages > $total)
1355 1355
 					{
1356
-						$numberOfMessages = $total%$_numberOfMessages;
1356
+						$numberOfMessages = $total % $_numberOfMessages;
1357 1357
 						//$numberOfMessages = abs($_startMessage-$total-1);
1358
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1358
+						if ($numberOfMessages > 0 && $numberOfMessages <= $_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1359 1359
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1360 1360
 					}
1361
-					$startMessage=($total-$_numberOfMessages)-1;
1361
+					$startMessage = ($total - $_numberOfMessages) - 1;
1362 1362
 					//$retValue['info']['first'] = $startMessage;
1363 1363
 					//$retValue['info']['last'] = $total;
1364 1364
 
1365 1365
 				}
1366
-				if ($startMessage+$_numberOfMessages>$total)
1366
+				if ($startMessage + $_numberOfMessages > $total)
1367 1367
 				{
1368
-					$_numberOfMessages = $_numberOfMessages-($total-($startMessage+$_numberOfMessages));
1368
+					$_numberOfMessages = $_numberOfMessages - ($total - ($startMessage + $_numberOfMessages));
1369 1369
 					//$retValue['info']['first'] = $startMessage;
1370 1370
 					//$retValue['info']['last'] = $total;
1371 1371
 				}
1372
-				if($startMessage > 0) {
1373
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1374
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1372
+				if ($startMessage > 0) {
1373
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + $startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1374
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + $startMessage), -$startMessage);
1375 1375
 				} else {
1376
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1377
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1376
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + ($_startMessage - 1))).', AllTheRest, Number of Messages:'.count($sortResult));
1377
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + ($_startMessage - 1)));
1378 1378
 				}
1379 1379
 				$sortResult = array_reverse($sortResult);
1380 1380
 			} else {
1381
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1382
-				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1381
+				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage - 1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1382
+				$sortResult = array_slice($sortResult, $_startMessage - 1, $_numberOfMessages);
1383 1383
 			}
1384 1384
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1385 1385
 		}
1386 1386
 		else
1387 1387
 		{
1388
-			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly:(array)$_thisUIDOnly);
1388
+			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly : (array)$_thisUIDOnly);
1389 1389
 		}
1390 1390
 
1391 1391
 
1392 1392
 		// fetch the data for the selected messages
1393
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1393
+		if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1394 1394
 		try
1395 1395
 		{
1396 1396
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1399,22 +1399,22 @@  discard block
 block discarded – undo
1399 1399
 			$fquery = new Horde_Imap_Client_Fetch_Query();
1400 1400
 
1401 1401
 			// Pre-cache the headers we want, 'fetchHeaders' is a label into the cache
1402
-			$fquery->headers('fetchHeaders',array(
1403
-				'DISPOSITION-NOTIFICATION-TO','RETURN-RECEIPT-TO','X-CONFIRM-READING-TO',
1404
-				'DATE','SUBJECT','FROM','TO','CC',
1402
+			$fquery->headers('fetchHeaders', array(
1403
+				'DISPOSITION-NOTIFICATION-TO', 'RETURN-RECEIPT-TO', 'X-CONFIRM-READING-TO',
1404
+				'DATE', 'SUBJECT', 'FROM', 'TO', 'CC',
1405 1405
 				'X-PRIORITY'
1406
-			),array(
1406
+			), array(
1407 1407
 				// Cache headers, we'll look at them below
1408
-				'cache' => true,//$_cacheResult,
1408
+				'cache' => true, //$_cacheResult,
1409 1409
 				// Set peek so messages are not flagged as read
1410 1410
 				'peek' => true
1411 1411
 			));
1412 1412
 			$fquery->size();
1413 1413
 			$fquery->structure();
1414 1414
 			$fquery->flags();
1415
-			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1415
+			$fquery->imapDate(); // needed to ensure getImapDate fetches the internaldate, not the current time
1416 1416
 			// if $_fetchPreviews is activated fetch part of the messages too
1417
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1417
+			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true, 'length'=>((int)$_fetchPreviews < 5000 ? 5000 : $_fetchPreviews), 'start'=>0));
1418 1418
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1419 1419
 				'ids' => $uidsToFetch,
1420 1420
 			));
@@ -1425,9 +1425,9 @@  discard block
 block discarded – undo
1425 1425
 			$headersNew = array();
1426 1426
 			$sortResult = array();
1427 1427
 		}
1428
-		if (self::$debug||self::$debugTimes)
1428
+		if (self::$debug || self::$debugTimes)
1429 1429
 		{
1430
-			self::logRunTimes($starttime,null,'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter),__METHOD__.' ('.__LINE__.') ');
1430
+			self::logRunTimes($starttime, null, 'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter), __METHOD__.' ('.__LINE__.') ');
1431 1431
 			if (self::$debug)
1432 1432
 			{
1433 1433
 				$queryString = implode(',', $sortResult);
@@ -1437,28 +1437,28 @@  discard block
 block discarded – undo
1437 1437
 
1438 1438
 		$cnt = 0;
1439 1439
 
1440
-		foreach((array)$sortResult as $uid) {
1440
+		foreach ((array)$sortResult as $uid) {
1441 1441
 			$sortOrder[$uid] = $cnt++;
1442 1442
 		}
1443 1443
 
1444 1444
 		$count = 0;
1445 1445
 		if (is_object($headersNew)) {
1446
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1447
-			foreach($headersNew->ids() as $id) {
1446
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1447
+			foreach ($headersNew->ids() as $id) {
1448 1448
 				$_headerObject = $headersNew->get($id);
1449 1449
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1450 1450
 				$headerObject = array();
1451
-				$uid = $headerObject['UID']= ($_headerObject->getUid()?$_headerObject->getUid():$id);
1451
+				$uid = $headerObject['UID'] = ($_headerObject->getUid() ? $_headerObject->getUid() : $id);
1452 1452
 				$headerObject['MSG_NUM'] = $_headerObject->getSeq();
1453 1453
 				$headerObject['SIZE'] = $_headerObject->getSize();
1454 1454
 				$headerObject['INTERNALDATE'] = $_headerObject->getImapDate();
1455 1455
 
1456 1456
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1457
-				$headerForPrio = array_change_key_case($_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1457
+				$headerForPrio = array_change_key_case($_headerObject->getHeaders('fetchHeaders', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1458 1458
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1459
-				if (empty($headerForPrio)) $headerForPrio = array_change_key_case($_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1459
+				if (empty($headerForPrio)) $headerForPrio = array_change_key_case($_headerObject->getHeaders('', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1460 1460
 				if (self::$debug) {
1461
-					error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject).'UID:'.$_headerObject->getUid().' Size:'.$_headerObject->getSize().' Date:'.$_headerObject->getImapDate().'/'.DateTime::to($_headerObject->getImapDate(),'Y-m-d H:i:s'));
1461
+					error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject).'UID:'.$_headerObject->getUid().' Size:'.$_headerObject->getSize().' Date:'.$_headerObject->getImapDate().'/'.DateTime::to($_headerObject->getImapDate(), 'Y-m-d H:i:s'));
1462 1462
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1463 1463
 				}
1464 1464
 
@@ -1468,21 +1468,21 @@  discard block
 block discarded – undo
1468 1468
 					$total--;
1469 1469
 					continue;
1470 1470
 				}
1471
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1471
+				if (isset($headerForPrio['DISPOSITION-NOTIFICATION-TO'])) {
1472 1472
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1473
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1473
+				} else if (isset($headerForPrio['RETURN-RECEIPT-TO'])) {
1474 1474
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1475
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1475
+				} else if (isset($headerForPrio['X-CONFIRM-READING-TO'])) {
1476 1476
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1477 1477
 				} /*else $sent_not = "";*/
1478 1478
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1479 1479
 				$headerObject['DATE'] = $headerForPrio['DATE'];
1480
-				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT'])?$headerForPrio['SUBJECT'][0]:$headerForPrio['SUBJECT']);
1481
-				$headerObject['FROM'] = (array)($headerForPrio['FROM']?$headerForPrio['FROM']:($headerForPrio['REPLY-TO']?$headerForPrio['REPLY-TO']:$headerForPrio['RETURN-PATH']));
1480
+				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT']) ? $headerForPrio['SUBJECT'][0] : $headerForPrio['SUBJECT']);
1481
+				$headerObject['FROM'] = (array)($headerForPrio['FROM'] ? $headerForPrio['FROM'] : ($headerForPrio['REPLY-TO'] ? $headerForPrio['REPLY-TO'] : $headerForPrio['RETURN-PATH']));
1482 1482
 				$headerObject['TO'] = (array)$headerForPrio['TO'];
1483
-				$headerObject['CC'] = isset($headerForPrio['CC'])?(array)$headerForPrio['CC']:array();
1484
-				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY'])?$headerForPrio['X-PRIORITY']:null;
1485
-				foreach (array('FROM','TO','CC') as $key)
1483
+				$headerObject['CC'] = isset($headerForPrio['CC']) ? (array)$headerForPrio['CC'] : array();
1484
+				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY']) ? $headerForPrio['X-PRIORITY'] : null;
1485
+				foreach (array('FROM', 'TO', 'CC') as $key)
1486 1486
 				{
1487 1487
 					$address = array();
1488 1488
 					foreach ($headerObject[$key] as $k => $ad)
@@ -1504,13 +1504,13 @@  discard block
 block discarded – undo
1504 1504
 						foreach ($rfcAddr as $_rfcAddr)
1505 1505
 						{
1506 1506
 							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1507
-							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1507
+							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox, $_rfcAddr->host, $_rfcAddr->personal);
1508 1508
 						}
1509 1509
 					}
1510 1510
 					$headerObject[$key] = $address;
1511 1511
 				}
1512 1512
 				$headerObject['FLAGS'] = $_headerObject->getFlags();
1513
-				$headerObject['BODYPREVIEW']=null;
1513
+				$headerObject['BODYPREVIEW'] = null;
1514 1514
 				// this section fetches part of the message-body (if enabled) for some kind of preview
1515 1515
 				// if we fail to succeed, we fall back to the retrieval of the message-body with
1516 1516
 				// fetchPartContents (see below, when we iterate over the structure to determine the
@@ -1520,17 +1520,17 @@  discard block
 block discarded – undo
1520 1520
 					$bodyPreview = $_headerObject->getFullMsg();
1521 1521
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
1522 1522
 					$base = Horde_Mime_Part::parseMessage($bodyPreview);
1523
-					foreach($base->partIterator() as $part)
1523
+					foreach ($base->partIterator() as $part)
1524 1524
 					{
1525 1525
 						//error_log(__METHOD__.__LINE__.'Part:'.$part->getPrimaryType());
1526
-						if (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'text')
1526
+						if (empty($headerObject['BODYPREVIEW']) && $part->getPrimaryType() == 'text')
1527 1527
 						{
1528 1528
 							$charset = $part->getContentTypeParameter('charset');
1529 1529
 							$buffer = Mail\Html::convertHTMLToText($part->toString(array(
1530
-												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1530
+												'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset
1531 1531
 											)), $charset, 'utf-8');
1532
-							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1533
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1532
+							$headerObject['BODYPREVIEW'] = trim(str_replace(array("\r\n", "\r", "\n"), ' ', mb_substr(Translation::convert_jsonsafe($buffer), 0, ((int)$_fetchPreviews < 300 ? 300 : $_fetchPreviews))));
1533
+						} elseif (empty($headerObject['BODYPREVIEW']) && $part->getPrimaryType() == 'multipart')
1534 1534
 						{
1535 1535
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1536 1536
 						}
@@ -1541,12 +1541,12 @@  discard block
 block discarded – undo
1541 1541
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1542 1542
 				//error_log(__METHOD__.' ('.__LINE__.') '.' MimeMap:'.array2string($mailStructureObject->contentTypeMap()));
1543 1543
 				//foreach ($_headerObject->getStructure()->getParts() as $p => $part)
1544
-				$headerObject['ATTACHMENTS']=null;
1545
-				$skipParts=array();
1546
-				$messageMimeType='';
1544
+				$headerObject['ATTACHMENTS'] = null;
1545
+				$skipParts = array();
1546
+				$messageMimeType = '';
1547 1547
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1548 1548
 				{
1549
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1549
+					if ($mime_id == 0 || $messageMimeType === '') $messageMimeType = $mime_type;
1550 1550
 					$part = $mailStructureObject->getPart($mime_id);
1551 1551
 					$partdisposition = $part->getDisposition();
1552 1552
 					$partPrimaryType = $part->getPrimaryType();
@@ -1554,16 +1554,16 @@  discard block
 block discarded – undo
1554 1554
 					// drawback here it is talking to the mailserver for each mail thus consuming
1555 1555
 					// more time than expected; so we call this section only when there is no
1556 1556
 					// bodypreview could be found (multipart/....)
1557
-					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1557
+					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW']) && ($partPrimaryType == 'text') &&
1558 1558
 						((intval($mime_id) === 1) || !$mime_id) &&
1559 1559
 						($partdisposition !== 'attachment')) {
1560
-							$_structure=$part;
1561
-							$this->fetchPartContents($uid, $_structure, false,true);
1562
-							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1563
-							$charSet=Translation::detect_encoding($headerObject['BODYPREVIEW']);
1560
+							$_structure = $part;
1561
+							$this->fetchPartContents($uid, $_structure, false, true);
1562
+							$headerObject['BODYPREVIEW'] = trim(str_replace(array("\r\n", "\r", "\n"), ' ', mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()), 0, ((int)$_fetchPreviews < 300 ? 300 : $_fetchPreviews))));
1563
+							$charSet = Translation::detect_encoding($headerObject['BODYPREVIEW']);
1564 1564
 							// add line breaks to $bodyParts
1565 1565
 							//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
1566
-							$headerObject['BODYPREVIEW']  = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
1566
+							$headerObject['BODYPREVIEW'] = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
1567 1567
 							//error_log(__METHOD__.__LINE__.$headerObject['BODYPREVIEW']);
1568 1568
 					}
1569 1569
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType);
@@ -1573,28 +1573,28 @@  discard block
 block discarded – undo
1573 1573
 						// the presence of an cid does not necessarily indicate its inline. it may lack the needed
1574 1574
 						// link to show the image. Considering this: we "list" everything that matches the above criteria
1575 1575
 						// as attachment in order to not loose/miss information on our data
1576
-						$partdisposition='attachment';//($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1576
+						$partdisposition = 'attachment'; //($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1577 1577
 					}
1578
-					if ($mime_type=='message/rfc822')
1578
+					if ($mime_type == 'message/rfc822')
1579 1579
 					{
1580 1580
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1581
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1581
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
1582 1582
 					}
1583 1583
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1584
-					if (array_key_exists($mime_id,$skipParts)) continue;
1585
-					if ($partdisposition=='attachment' ||
1586
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1587
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
1588
-						($partdisposition=='inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1584
+					if (array_key_exists($mime_id, $skipParts)) continue;
1585
+					if ($partdisposition == 'attachment' ||
1586
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && $mime_type == 'image/tiff') || // as we are not able to display tiffs
1587
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && empty($cid)) ||
1588
+						($partdisposition == 'inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1589 1589
 					{
1590
-						$headerObject['ATTACHMENTS'][$mime_id]=$part->getAllDispositionParameters();
1591
-						$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=$mime_type;
1592
-						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1590
+						$headerObject['ATTACHMENTS'][$mime_id] = $part->getAllDispositionParameters();
1591
+						$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] = $mime_type;
1592
+						$headerObject['ATTACHMENTS'][$mime_id]['uid'] = $uid;
1593 1593
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1594
-						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1595
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1596
-						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1597
-							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1594
+						$headerObject['ATTACHMENTS'][$mime_id]['partID'] = $mime_id;
1595
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name'] = $part->getName();
1596
+						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'], 'winmail.dat') ||
1597
+							$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] == 'application/ms-tnef')
1598 1598
 						{
1599 1599
 							$headerObject['ATTACHMENTS'][$mime_id]['is_winmail'] = true;
1600 1600
 						}
@@ -1609,54 +1609,54 @@  discard block
 block discarded – undo
1609 1609
 				if (empty($headerObject['UID'])) continue;
1610 1610
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1611 1611
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1612
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1612
+				if (substr($headerObject['DATE'], -2) === 'UT') {
1613 1613
 					$headerObject['DATE'] .= 'C';
1614 1614
 				}
1615
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1615
+				if (substr($headerObject['INTERNALDATE'], -2) === 'UT') {
1616 1616
 					$headerObject['INTERNALDATE'] .= 'C';
1617 1617
 				}
1618 1618
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1619 1619
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1620
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1621
-				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1622
-				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1623
-				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
1624
-				$retValue['header'][$sortOrder[$uid]]['internaldate']= self::_strtotime($headerObject['INTERNALDATE'],'ts',true);
1625
-				$retValue['header'][$sortOrder[$uid]]['mimetype']	= $messageMimeType;
1626
-				$retValue['header'][$sortOrder[$uid]]['id']		= $headerObject['MSG_NUM'];
1627
-				$retValue['header'][$sortOrder[$uid]]['uid']		= $headerObject['UID'];
1628
-				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1629
-				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1620
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][] = $a; }
1621
+				$retValue['header'][$sortOrder[$uid]]['subject'] = $this->decode_subject($headerObject['SUBJECT']);
1622
+				$retValue['header'][$sortOrder[$uid]]['size'] = $headerObject['SIZE'];
1623
+				$retValue['header'][$sortOrder[$uid]]['date'] = self::_strtotime(($headerObject['DATE'] && !($headerObject['DATE'] == 'NIL') ? $headerObject['DATE'] : $headerObject['INTERNALDATE']), 'ts', true);
1624
+				$retValue['header'][$sortOrder[$uid]]['internaldate'] = self::_strtotime($headerObject['INTERNALDATE'], 'ts', true);
1625
+				$retValue['header'][$sortOrder[$uid]]['mimetype'] = $messageMimeType;
1626
+				$retValue['header'][$sortOrder[$uid]]['id'] = $headerObject['MSG_NUM'];
1627
+				$retValue['header'][$sortOrder[$uid]]['uid'] = $headerObject['UID'];
1628
+				$retValue['header'][$sortOrder[$uid]]['bodypreview'] = $headerObject['BODYPREVIEW'];
1629
+				$retValue['header'][$sortOrder[$uid]]['priority'] = ($headerObject['PRIORITY'] ? $headerObject['PRIORITY'] : 3);
1630 1630
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1631 1631
 				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1632 1632
 				if (is_array($headerObject['FLAGS'])) {
1633
-					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1633
+					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]], self::prepareFlagsArray($headerObject));
1634 1634
 				}
1635 1635
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1636
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1637
-					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1636
+				if (is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1637
+					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0], true);
1638 1638
 				}
1639
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1640
-					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1641
-					if (count($headerObject['TO'])>1)
1639
+				if (is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1640
+					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0], true);
1641
+					if (count($headerObject['TO']) > 1)
1642 1642
 					{
1643
-						$ki=0;
1644
-						foreach($headerObject['TO'] as $k => $add)
1643
+						$ki = 0;
1644
+						foreach ($headerObject['TO'] as $k => $add)
1645 1645
 						{
1646
-							if ($k==0) continue;
1646
+							if ($k == 0) continue;
1647 1647
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1648
-							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1648
+							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add, true);
1649 1649
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1650 1650
 							$ki++;
1651 1651
 						}
1652 1652
 					}
1653 1653
 				}
1654
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
1655
-					$ki=0;
1656
-					foreach($headerObject['CC'] as $k => $add)
1654
+				if (is_array($headerObject['CC']) && count($headerObject['CC']) > 0) {
1655
+					$ki = 0;
1656
+					foreach ($headerObject['CC'] as $k => $add)
1657 1657
 					{
1658 1658
 						//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1659
-						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add,true);
1659
+						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add, true);
1660 1660
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1661 1661
 						$ki++;
1662 1662
 					}
@@ -1665,27 +1665,27 @@  discard block
 block discarded – undo
1665 1665
 
1666 1666
 				$count++;
1667 1667
 			}
1668
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1668
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' fetching Headers and stuff for Folder:'.$_folderName, __METHOD__.' ('.__LINE__.') ');
1669 1669
 			//self::$debug=false;
1670 1670
 			// sort the messages to the requested displayorder
1671
-			if(is_array($retValue['header'])) {
1671
+			if (is_array($retValue['header'])) {
1672 1672
 				$countMessages = $total;
1673 1673
 				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1674 1674
 				ksort($retValue['header']);
1675 1675
 				$retValue['info']['total']	= $total;
1676 1676
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1677 1677
 				$retValue['info']['first']	= $_startMessage;
1678
-				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1678
+				$retValue['info']['last'] = $_startMessage + $count - 1;
1679 1679
 				return $retValue;
1680 1680
 			} else {
1681 1681
 				$retValue = array();
1682 1682
 				$retValue['info']['total']	= 0;
1683 1683
 				$retValue['info']['first']	= 0;
1684
-				$retValue['info']['last']	= 0;
1684
+				$retValue['info']['last'] = 0;
1685 1685
 				return $retValue;
1686 1686
 			}
1687 1687
 		} else {
1688
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
1688
+			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew, TRUE));
1689 1689
 			$retValue = array();
1690 1690
 			$retValue['info']['total']  = 0;
1691 1691
 			$retValue['info']['first']  = 0;
@@ -1702,17 +1702,17 @@  discard block
 block discarded – undo
1702 1702
 	 */
1703 1703
 	static function prepareFlagsArray($headerObject)
1704 1704
 	{
1705
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
1705
+		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower', $headerObject['FLAGS']);
1706 1706
 		$retValue = array();
1707 1707
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1708 1708
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
1709
-		$retValue['answered']	= in_array('\\answered', $headerFlags);
1710
-		$retValue['forwarded']   = in_array('$forwarded', $headerFlags);
1709
+		$retValue['answered'] = in_array('\\answered', $headerFlags);
1710
+		$retValue['forwarded'] = in_array('$forwarded', $headerFlags);
1711 1711
 		$retValue['deleted']	= in_array('\\deleted', $headerFlags);
1712
-		$retValue['seen']		= in_array('\\seen', $headerFlags);
1713
-		$retValue['draft']		= in_array('\\draft', $headerFlags);
1714
-		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags)||in_array('mdnsent', $headerFlags);
1715
-		$retValue['mdnnotsent']	= in_array('$mdnnotsent', $headerFlags)||in_array('mdnnotsent', $headerFlags);
1712
+		$retValue['seen'] = in_array('\\seen', $headerFlags);
1713
+		$retValue['draft'] = in_array('\\draft', $headerFlags);
1714
+		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags) || in_array('mdnsent', $headerFlags);
1715
+		$retValue['mdnnotsent'] = in_array('$mdnnotsent', $headerFlags) || in_array('mdnnotsent', $headerFlags);
1716 1716
 		$retValue['label1']   = in_array('$label1', $headerFlags);
1717 1717
 		$retValue['label2']   = in_array('$label2', $headerFlags);
1718 1718
 		$retValue['label3']   = in_array('$label3', $headerFlags);
@@ -1736,12 +1736,12 @@  discard block
 block discarded – undo
1736 1736
 	 * @param bool $setSession if set to true the session will be populated with the result of the query
1737 1737
 	 * @return mixed bool/array false or array of ids
1738 1738
 	 */
1739
-	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid=true, $setSession=true)
1739
+	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid = true, $setSession = true)
1740 1740
 	{
1741 1741
 		static $cachedFolderStatus = null;
1742 1742
 		// in the past we needed examineMailbox to figure out if the server with the serverID support keywords
1743 1743
 		// this information is filled/provided by examineMailbox; but caching within one request seems o.k.
1744
-		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]) )
1744
+		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]))
1745 1745
 		{
1746 1746
 			$folderStatus = $cachedFolderStatus[$this->profileID][$_folderName] = $this->icServer->examineMailbox($_folderName);
1747 1747
 		}
@@ -1753,27 +1753,27 @@  discard block
 block discarded – undo
1753 1753
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1754 1754
 		$try2useCache = true;
1755 1755
 		static $eMailListContainsDeletedMessages = null;
1756
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1756
+		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
1757 1757
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1758
-		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1758
+		if ($setSession == true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1759 1759
 		{
1760 1760
 			if (self::$debugTimes) $starttime = microtime(true);
1761
-			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1762
-			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five=true,false);
1761
+			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
1762
+			$deletedMessages = $this->getSortedList($_folderName, 0, $three = 1, array('status'=>array('DELETED')), $five = true, false);
1763 1763
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
1764
-			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1765
-			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1766
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');			//error_log(__METHOD__.' ('.__LINE__.') '.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
1764
+			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] = $deletedMessages['count'];
1765
+			Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), $eMailListContainsDeletedMessages, 60 * 60 * 1);
1766
+			if (self::$debugTimes) self::logRunTimes($starttime, null, 'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName], __METHOD__.' ('.__LINE__.') '); //error_log(__METHOD__.' ('.__LINE__.') '.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
1767 1767
 		}
1768 1768
 		$try2useCache = false;
1769 1769
 		//self::$supportsORinQuery[$this->profileID]=true;
1770 1770
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1771 1771
 		{
1772
-			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1773
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
1772
+			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
1773
+			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID] = true;
1774 1774
 		}
1775 1775
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1776
-		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
1776
+		$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1777 1777
 		if (self::$debug)
1778 1778
 		{
1779 1779
 			$query_str = $filter->build();
@@ -1781,14 +1781,14 @@  discard block
 block discarded – undo
1781 1781
 		}
1782 1782
 		//_debug_array($filter);
1783 1783
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1784
-		if($this->icServer->hasCapability('SORT')) {
1784
+		if ($this->icServer->hasCapability('SORT')) {
1785 1785
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1786 1786
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1787 1787
 			// there is no messing with the dates)
1788 1788
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1789 1789
 			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
1790 1790
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1791
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1791
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE, $sortOrder)) $_reverse = false; // as we reversed the result already
1792 1792
 			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
1793 1793
 			try
1794 1794
 			{
@@ -1796,24 +1796,24 @@  discard block
 block discarded – undo
1796 1796
 					'sort' => $sortOrder,));
1797 1797
 			// if there is an Error, we assume that the server is not capable of sorting
1798 1798
 			}
1799
-			catch(\Exception $e)
1799
+			catch (\Exception $e)
1800 1800
 			{
1801 1801
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1802 1802
 				$resultByUid = false;
1803 1803
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1804
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1804
+				if ($_reverse) array_unshift($sortOrder, Horde_Imap_Client::SORT_REVERSE);
1805 1805
 				try
1806 1806
 				{
1807 1807
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
1808 1808
 						'sort' => $sortOrder));
1809 1809
 				}
1810
-				catch(\Exception $e)
1810
+				catch (\Exception $e)
1811 1811
 				{
1812 1812
 					error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1813 1813
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1814 1814
 				}
1815 1815
 			}
1816
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1816
+			if (self::$debug) error_log(__METHOD__.print_r($sortResult, true));
1817 1817
 		} else {
1818 1818
 			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
1819 1819
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
@@ -1823,12 +1823,12 @@  discard block
 block discarded – undo
1823 1823
 				$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1824 1824
 					'sort' => $sortOrder)*/);
1825 1825
 			}
1826
-			catch(\Exception $e)
1826
+			catch (\Exception $e)
1827 1827
 			{
1828 1828
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1829 1829
 				// possible error OR Query. But Horde gives no detailed Info :-(
1830
-				self::$supportsORinQuery[$this->profileID]=false;
1831
-				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1830
+				self::$supportsORinQuery[$this->profileID] = false;
1831
+				Cache::setCache(Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), self::$supportsORinQuery, 60 * 60 * 10);
1832 1832
 				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
1833 1833
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1834 1834
 				try
@@ -1836,25 +1836,25 @@  discard block
 block discarded – undo
1836 1836
 					$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1837 1837
 						'sort' => $sortOrder)*/);
1838 1838
 				}
1839
-				catch(\Exception $e)
1839
+				catch (\Exception $e)
1840 1840
 				{
1841 1841
 				}
1842 1842
 			}
1843
-			if(is_array($sortResult['match'])) {
1843
+			if (is_array($sortResult['match'])) {
1844 1844
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1845 1845
 					sort($sortResult['match'], SORT_NUMERIC);
1846 1846
 			}
1847
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1847
+			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter, true)." ->".print_r($sortResult, true));
1848 1848
 		}
1849 1849
 		if ($setSession)
1850 1850
 		{
1851 1851
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidValidity'] = $folderStatus['UIDVALIDITY'];
1852
-			self::$folderStatusCache[$this->profileID][$_folderName]['messages']	= $folderStatus['MESSAGES'];
1852
+			self::$folderStatusCache[$this->profileID][$_folderName]['messages'] = $folderStatus['MESSAGES'];
1853 1853
 			self::$folderStatusCache[$this->profileID][$_folderName]['deleted']	= $eMailListContainsDeletedMessages[$this->profileID][$_folderName];
1854 1854
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidnext']	= $folderStatus['UIDNEXT'];
1855
-			self::$folderStatusCache[$this->profileID][$_folderName]['filter']	= $_filter;
1855
+			self::$folderStatusCache[$this->profileID][$_folderName]['filter'] = $_filter;
1856 1856
 			self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'] = $sortResult;
1857
-			self::$folderStatusCache[$this->profileID][$_folderName]['sort']	= $_sort;
1857
+			self::$folderStatusCache[$this->profileID][$_folderName]['sort'] = $_sort;
1858 1858
 		}
1859 1859
 		//error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1860 1860
 		//_debug_array($sortResult['match']->ids);
@@ -1868,12 +1868,12 @@  discard block
 block discarded – undo
1868 1868
 	 * @param bool _reverse wether to add REVERSE to the Sort String or not
1869 1869
 	 * @return the sort sequence for horde search
1870 1870
 	 */
1871
-	function _getSortString($_sort, $_reverse=false)
1871
+	function _getSortString($_sort, $_reverse = false)
1872 1872
 	{
1873
-		$_reverse=false;
1873
+		$_reverse = false;
1874 1874
 		if (is_numeric($_sort))
1875 1875
 		{
1876
-			switch($_sort) {
1876
+			switch ($_sort) {
1877 1877
 				case 2:
1878 1878
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1879 1879
 					break;
@@ -1895,7 +1895,7 @@  discard block
 block discarded – undo
1895 1895
 		}
1896 1896
 		else
1897 1897
 		{
1898
-			switch(strtoupper($_sort)) {
1898
+			switch (strtoupper($_sort)) {
1899 1899
 				case 'FROMADDRESS':
1900 1900
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1901 1901
 					break;
@@ -1921,7 +1921,7 @@  discard block
 block discarded – undo
1921 1921
 					break;
1922 1922
 			}
1923 1923
 		}
1924
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
1924
+		if ($_reverse) array_unshift($retValue, Horde_Imap_Client::SORT_REVERSE);
1925 1925
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1926 1926
 		return $retValue;
1927 1927
 	}
@@ -1934,28 +1934,28 @@  discard block
 block discarded – undo
1934 1934
 	 * @param boolean $_supportsOrInQuery wether to use the OR Query on QuickSearch
1935 1935
 	 * @return Horde_Imap_Client_Search_Query the IMAP filter
1936 1936
 	 */
1937
-	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery=true)
1937
+	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery = true)
1938 1938
 	{
1939 1939
 		$imapFilter = new Horde_Imap_Client_Search_Query();
1940 1940
 		$imapFilter->charset('UTF-8');
1941 1941
 
1942 1942
 		//_debug_array($_criterias);
1943
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
1944
-		if((!is_array($_criterias) || $_criterias['status']=='any') &&
1943
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias) ? " none -> returning" : array2string($_criterias)));
1944
+		if ((!is_array($_criterias) || $_criterias['status'] == 'any') &&
1945 1945
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
1946
-			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
1947
-			( !empty($_criterias['range'])&& ($_criterias['range']!='BETWEEN' && empty($_criterias['date'])||
1948
-			($_criterias['range']=='BETWEEN' && empty($_criterias['since'])&& empty($_criterias['before']))))))
1946
+			(!isset($_criterias['range']) || empty($_criterias['range']) ||
1947
+			(!empty($_criterias['range']) && ($_criterias['range'] != 'BETWEEN' && empty($_criterias['date']) ||
1948
+			($_criterias['range'] == 'BETWEEN' && empty($_criterias['since']) && empty($_criterias['before']))))))
1949 1949
 		{
1950 1950
 			//error_log(__METHOD__.' ('.__LINE__.') returning early Criterias:'.print_r($_criterias, true));
1951
-			$imapFilter->flag('DELETED', $set=false);
1951
+			$imapFilter->flag('DELETED', $set = false);
1952 1952
 			return $imapFilter;
1953 1953
 		}
1954 1954
 		$queryValid = false;
1955 1955
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
1956 1956
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
1957 1957
 		$statusQueryValid = false;
1958
-		foreach((array)$_criterias['status'] as $k => $criteria) {
1958
+		foreach ((array)$_criterias['status'] as $k => $criteria) {
1959 1959
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
1960 1960
 			$imapStatusFilter->charset('UTF-8');
1961 1961
 			$criteria = strtoupper($criteria);
@@ -1965,12 +1965,12 @@  discard block
 block discarded – undo
1965 1965
 				case 'FLAGGED':
1966 1966
 				case 'RECENT':
1967 1967
 				case 'SEEN':
1968
-					$imapStatusFilter->flag($criteria, $set=true);
1969
-					$queryValid = $statusQueryValid =true;
1968
+					$imapStatusFilter->flag($criteria, $set = true);
1969
+					$queryValid = $statusQueryValid = true;
1970 1970
 					break;
1971 1971
 				case 'READ':
1972
-					$imapStatusFilter->flag('SEEN', $set=true);
1973
-					$queryValid = $statusQueryValid =true;
1972
+					$imapStatusFilter->flag('SEEN', $set = true);
1973
+					$queryValid = $statusQueryValid = true;
1974 1974
 					break;
1975 1975
 				case 'LABEL1':
1976 1976
 				case 'KEYWORD1':
@@ -1982,38 +1982,38 @@  discard block
 block discarded – undo
1982 1982
 				case 'KEYWORD4':
1983 1983
 				case 'LABEL5':
1984 1984
 				case 'KEYWORD5':
1985
-					$imapStatusFilter->flag(str_ireplace('KEYWORD','$LABEL',$criteria), $set=true);
1986
-					$queryValid = $statusQueryValid =true;
1985
+					$imapStatusFilter->flag(str_ireplace('KEYWORD', '$LABEL', $criteria), $set = true);
1986
+					$queryValid = $statusQueryValid = true;
1987 1987
 					break;
1988 1988
 				case 'NEW':
1989
-					$imapStatusFilter->flag('RECENT', $set=true);
1990
-					$imapStatusFilter->flag('SEEN', $set=false);
1991
-					$queryValid = $statusQueryValid =true;
1989
+					$imapStatusFilter->flag('RECENT', $set = true);
1990
+					$imapStatusFilter->flag('SEEN', $set = false);
1991
+					$queryValid = $statusQueryValid = true;
1992 1992
 					break;
1993 1993
 				case 'OLD':
1994
-					$imapStatusFilter->flag('RECENT', $set=false);
1995
-					$queryValid = $statusQueryValid =true;
1994
+					$imapStatusFilter->flag('RECENT', $set = false);
1995
+					$queryValid = $statusQueryValid = true;
1996 1996
 					break;
1997 1997
 // operate only on system flags
1998 1998
 //        $systemflags = array(
1999 1999
 //            'ANSWERED', 'DELETED', 'DRAFT', 'FLAGGED', 'RECENT', 'SEEN'
2000 2000
 //        );
2001 2001
 				case 'UNANSWERED':
2002
-					$imapStatusFilter->flag('ANSWERED', $set=false);
2003
-					$queryValid = $statusQueryValid =true;
2002
+					$imapStatusFilter->flag('ANSWERED', $set = false);
2003
+					$queryValid = $statusQueryValid = true;
2004 2004
 					break;
2005 2005
 				case 'UNDELETED':
2006
-					$imapFilter->flag('DELETED', $set=false);
2006
+					$imapFilter->flag('DELETED', $set = false);
2007 2007
 					$queryValid = true;
2008 2008
 					break;
2009 2009
 				case 'UNFLAGGED':
2010
-					$imapStatusFilter->flag('FLAGGED', $set=false);
2011
-					$queryValid = $statusQueryValid =true;
2010
+					$imapStatusFilter->flag('FLAGGED', $set = false);
2011
+					$queryValid = $statusQueryValid = true;
2012 2012
 					break;
2013 2013
 				case 'UNREAD':
2014 2014
 				case 'UNSEEN':
2015
-					$imapStatusFilter->flag('SEEN', $set=false);
2016
-					$queryValid = $statusQueryValid =true;
2015
+					$imapStatusFilter->flag('SEEN', $set = false);
2016
+					$queryValid = $statusQueryValid = true;
2017 2017
 					break;
2018 2018
 				case 'UNLABEL1':
2019 2019
 				case 'UNKEYWORD1':
@@ -2025,8 +2025,8 @@  discard block
 block discarded – undo
2025 2025
 				case 'UNKEYWORD4':
2026 2026
 				case 'UNLABEL5':
2027 2027
 				case 'UNKEYWORD5':
2028
-					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD','UNLABEL'),'$LABEL',$criteria), $set=false);
2029
-					$queryValid = $statusQueryValid =true;
2028
+					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD', 'UNLABEL'), '$LABEL', $criteria), $set = false);
2029
+					$queryValid = $statusQueryValid = true;
2030 2030
 					break;
2031 2031
 				default:
2032 2032
 					$statusQueryValid = false;
@@ -2042,20 +2042,20 @@  discard block
 block discarded – undo
2042 2042
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2043 2043
 		$imapSearchFilter->charset('UTF-8');
2044 2044
 
2045
-		if(!empty($_criterias['string'])) {
2045
+		if (!empty($_criterias['string'])) {
2046 2046
 			$criteria = strtoupper($_criterias['type']);
2047 2047
 			switch ($criteria) {
2048 2048
 				case 'BYDATE':
2049 2049
 				case 'QUICK':
2050 2050
 				case 'QUICKWITHCC':
2051
-					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not=false);
2051
+					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not = false);
2052 2052
 					//$imapSearchFilter->charset('UTF-8');
2053 2053
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2054 2054
 					$imapFilter2->charset('UTF-8');
2055
-					if($this->isSentFolder($_folder)) {
2056
-						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2055
+					if ($this->isSentFolder($_folder)) {
2056
+						$imapFilter2->headerText('TO', $_criterias['string'], $not = false);
2057 2057
 					} else {
2058
-						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2058
+						$imapFilter2->headerText('FROM', $_criterias['string'], $not = false);
2059 2059
 					}
2060 2060
 					if ($_supportsOrInQuery)
2061 2061
 					{
@@ -2065,31 +2065,31 @@  discard block
 block discarded – undo
2065 2065
 					{
2066 2066
 						$imapSearchFilter->andSearch($imapFilter2);
2067 2067
 					}
2068
-					if ($_supportsOrInQuery && $criteria=='QUICKWITHCC')
2068
+					if ($_supportsOrInQuery && $criteria == 'QUICKWITHCC')
2069 2069
 					{
2070 2070
 						$imapFilter3 = new Horde_Imap_Client_Search_Query();
2071 2071
 						$imapFilter3->charset('UTF-8');
2072
-						$imapFilter3->headerText('CC', $_criterias['string'], $not=false);
2072
+						$imapFilter3->headerText('CC', $_criterias['string'], $not = false);
2073 2073
 						$imapSearchFilter->orSearch($imapFilter3);
2074 2074
 					}
2075 2075
 					$queryValid = true;
2076 2076
 					break;
2077 2077
 				case 'LARGER':
2078 2078
 				case 'SMALLER':
2079
-					if (strlen(trim($_criterias['string'])) != strlen((float) trim($_criterias['string'])))
2079
+					if (strlen(trim($_criterias['string'])) != strlen((float)trim($_criterias['string'])))
2080 2080
 					{
2081 2081
 						//examine string to evaluate size
2082
-						$unit = strtoupper(trim(substr(trim($_criterias['string']),strlen((float) trim($_criterias['string'])))));
2083
-						$multipleBy = array('KB'=>1024,'K'=>1024,
2084
-											'MB'=>1024*1000,'M'=>1024*1000,
2085
-											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2086
-											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2087
-						$numberinBytes=(float)$_criterias['string'];
2088
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2082
+						$unit = strtoupper(trim(substr(trim($_criterias['string']), strlen((float)trim($_criterias['string'])))));
2083
+						$multipleBy = array('KB'=>1024, 'K'=>1024,
2084
+											'MB'=>1024 * 1000, 'M'=>1024 * 1000,
2085
+											'GB'=>1024 * 1000 * 1000, 'G'=>1024 * 1000 * 1000,
2086
+											'TB'=>1024 * 1000 * 1000 * 1000, 'T'=>1024 * 1000 * 1000 * 1000);
2087
+						$numberinBytes = (float)$_criterias['string'];
2088
+						if (isset($multipleBy[$unit])) $numberinBytes = (float)$_criterias['string'] * $multipleBy[$unit];
2089 2089
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2090
-						$_criterias['string']=$numberinBytes;
2090
+						$_criterias['string'] = $numberinBytes;
2091 2091
 					}
2092
-					$imapSearchFilter->size( $_criterias['string'], ($criteria=='LARGER'?true:false), $not=false);
2092
+					$imapSearchFilter->size($_criterias['string'], ($criteria == 'LARGER' ? true : false), $not = false);
2093 2093
 					//$imapSearchFilter->charset('UTF-8');
2094 2094
 					$queryValid = true;
2095 2095
 					break;
@@ -2098,31 +2098,31 @@  discard block
 block discarded – undo
2098 2098
 				case 'CC':
2099 2099
 				case 'BCC':
2100 2100
 				case 'SUBJECT':
2101
-					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not=false);
2101
+					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not = false);
2102 2102
 					//$imapSearchFilter->charset('UTF-8');
2103 2103
 					$queryValid = true;
2104 2104
 					break;
2105 2105
 				case 'BODY':
2106 2106
 				case 'TEXT':
2107
-					$imapSearchFilter->text($_criterias['string'],($criteria=='BODY'?true:false), $not=false);
2107
+					$imapSearchFilter->text($_criterias['string'], ($criteria == 'BODY' ? true : false), $not = false);
2108 2108
 					//$imapSearchFilter->charset('UTF-8');
2109 2109
 					$queryValid = true;
2110 2110
 					break;
2111 2111
 				case 'SINCE':
2112
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2112
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2113 2113
 					$queryValid = true;
2114 2114
 					break;
2115 2115
 				case 'BEFORE':
2116
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2116
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2117 2117
 					$queryValid = true;
2118 2118
 					break;
2119 2119
 				case 'ON':
2120
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header=true, $not=false);
2120
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header = true, $not = false);
2121 2121
 					$queryValid = true;
2122 2122
 					break;
2123 2123
 			}
2124 2124
 		}
2125
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2125
+		if ($statusQueryValid && !$queryValid) $queryValid = true;
2126 2126
 		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2127 2127
 
2128 2128
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
@@ -2131,12 +2131,12 @@  discard block
 block discarded – undo
2131 2131
 			$imapRangeFilter = new Horde_Imap_Client_Search_Query();
2132 2132
 			$imapRangeFilter->charset('UTF-8');
2133 2133
 			$criteria = strtoupper($_criterias['range']);
2134
-			if ($_criterias['range'] == "BETWEEN" && isset($_criterias['since']) && isset($_criterias['before']) && $_criterias['since']==$_criterias['before'])
2134
+			if ($_criterias['range'] == "BETWEEN" && isset($_criterias['since']) && isset($_criterias['before']) && $_criterias['since'] == $_criterias['before'])
2135 2135
 			{
2136
-				$_criterias['date']=$_criterias['since'];
2136
+				$_criterias['date'] = $_criterias['since'];
2137 2137
 				unset($_criterias['since']);
2138 2138
 				unset($_criterias['before']);
2139
-				$criteria=$_criterias['range']='ON';
2139
+				$criteria = $_criterias['range'] = 'ON';
2140 2140
 			}
2141 2141
 			switch ($criteria) {
2142 2142
 				case 'BETWEEN':
@@ -2144,7 +2144,7 @@  discard block
 block discarded – undo
2144 2144
 					//enddate
2145 2145
 					if ($_criterias['since'])
2146 2146
 					{
2147
-						$imapRangeFilter->dateSearch(new DateTime($_criterias['since']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2147
+						$imapRangeFilter->dateSearch(new DateTime($_criterias['since']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2148 2148
 						$rangeValid = true;
2149 2149
 					}
2150 2150
 					//startdate
@@ -2153,28 +2153,28 @@  discard block
 block discarded – undo
2153 2153
 						$imapRangeFilter2 = new Horde_Imap_Client_Search_Query();
2154 2154
 						$imapRangeFilter2->charset('UTF-8');
2155 2155
 						//our before (startdate) is inklusive, as we work with "d-M-Y", we must add a day
2156
-						$_criterias['before'] = date("d-M-Y",DateTime::to($_criterias['before'],'ts')+(3600*24));
2157
-						$imapRangeFilter2->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2156
+						$_criterias['before'] = date("d-M-Y", DateTime::to($_criterias['before'], 'ts') + (3600 * 24));
2157
+						$imapRangeFilter2->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2158 2158
 						$imapRangeFilter->andSearch($imapRangeFilter2);
2159 2159
 						$rangeValid = true;
2160 2160
 					}
2161 2161
 					break;
2162 2162
 				case 'SINCE'://enddate
2163
-					$imapRangeFilter->dateSearch(new DateTime(($_criterias['since']?$_criterias['since']:$_criterias['date'])), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2163
+					$imapRangeFilter->dateSearch(new DateTime(($_criterias['since'] ? $_criterias['since'] : $_criterias['date'])), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2164 2164
 					$rangeValid = true;
2165 2165
 					break;
2166 2166
 				case 'BEFORE'://startdate
2167 2167
 					//our before (startdate) is inklusive, as we work with "d-M-Y", we must add a day
2168
-					$_criterias['before'] = date("d-M-Y",DateTime::to(($_criterias['before']?$_criterias['before']:$_criterias['date']),'ts')+(3600*24));
2169
-					$imapRangeFilter->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2168
+					$_criterias['before'] = date("d-M-Y", DateTime::to(($_criterias['before'] ? $_criterias['before'] : $_criterias['date']), 'ts') + (3600 * 24));
2169
+					$imapRangeFilter->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2170 2170
 					$rangeValid = true;
2171 2171
 					break;
2172 2172
 				case 'ON':
2173
-					$imapRangeFilter->dateSearch(new DateTime($_criterias['date']), Horde_Imap_Client_Search_Query::DATE_ON, $header=true, $not=false);
2173
+					$imapRangeFilter->dateSearch(new DateTime($_criterias['date']), Horde_Imap_Client_Search_Query::DATE_ON, $header = true, $not = false);
2174 2174
 					$rangeValid = true;
2175 2175
 					break;
2176 2176
 			}
2177
-			if ($rangeValid && !$queryValid) $queryValid=true;
2177
+			if ($rangeValid && !$queryValid) $queryValid = true;
2178 2178
 			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2179 2179
 		}
2180 2180
 		if (self::$debug)
@@ -2183,8 +2183,8 @@  discard block
 block discarded – undo
2183 2183
 			$query_str = $imapFilter->build();
2184 2184
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2185 2185
 		}
2186
-		if($queryValid==false) {
2187
-			$imapFilter->flag('DELETED', $set=false);
2186
+		if ($queryValid == false) {
2187
+			$imapFilter->flag('DELETED', $set = false);
2188 2188
 			return $imapFilter;
2189 2189
 		} else {
2190 2190
 			return $imapFilter;
@@ -2198,11 +2198,11 @@  discard block
 block discarded – undo
2198 2198
 	 * @param  mixed/boolean $_tryIDNConversion (true/false AND FORCE): try IDN Conversion on domainparts of emailADRESSES
2199 2199
 	 * @return mixed - based on the input type
2200 2200
 	 */
2201
-	static function decode_header($_string, $_tryIDNConversion=false)
2201
+	static function decode_header($_string, $_tryIDNConversion = false)
2202 2202
 	{
2203 2203
 		if (is_array($_string))
2204 2204
 		{
2205
-			foreach($_string as $k=>$v)
2205
+			foreach ($_string as $k=>$v)
2206 2206
 			{
2207 2207
 				$_string[$k] = self::decode_header($v, $_tryIDNConversion);
2208 2208
 			}
@@ -2210,18 +2210,18 @@  discard block
 block discarded – undo
2210 2210
 		}
2211 2211
 		else
2212 2212
 		{
2213
-			$_string = Mail\Html::decodeMailHeader($_string,self::$displayCharset);
2213
+			$_string = Mail\Html::decodeMailHeader($_string, self::$displayCharset);
2214 2214
 			$test = @json_encode($_string);
2215 2215
 			//error_log(__METHOD__.__LINE__.' ->'.strlen($singleBodyPart['body']).' Error:'.json_last_error().'<- BodyPart:#'.$test.'#');
2216
-			if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2216
+			if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2217 2217
 			{
2218 2218
 				// try to fix broken utf8
2219 2219
 				$x = utf8_encode($_string);
2220 2220
 				$test = @json_encode($x);
2221
-				if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2221
+				if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2222 2222
 				{
2223 2223
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
2224
-					$_string = (function_exists('mb_convert_encoding')?mb_convert_encoding($_string,'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$_string):$_string));
2224
+					$_string = (function_exists('mb_convert_encoding') ? mb_convert_encoding($_string, 'UTF-8', 'UTF-8') : (function_exists('iconv') ? @iconv("UTF-8", "UTF-8//IGNORE", $_string) : $_string));
2225 2225
 				}
2226 2226
 				else
2227 2227
 				{
@@ -2229,7 +2229,7 @@  discard block
 block discarded – undo
2229 2229
 				}
2230 2230
 			}
2231 2231
 
2232
-			if ($_tryIDNConversion===true && stripos($_string,'@')!==false)
2232
+			if ($_tryIDNConversion === true && stripos($_string, '@') !== false)
2233 2233
 			{
2234 2234
 				$rfcAddr = self::parseAddressList($_string);
2235 2235
 				$stringA = array();
@@ -2241,11 +2241,11 @@  discard block
 block discarded – undo
2241 2241
 						$stringA = array();
2242 2242
 						break; // skip idna conversion if we encounter an error here
2243 2243
 					}
2244
-					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2244
+					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox, Horde_Idna::decode($_rfcAddr->host), $_rfcAddr->personal);
2245 2245
 				}
2246
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2246
+				if (!empty($stringA)) $_string = implode(',', $stringA);
2247 2247
 			}
2248
-			if ($_tryIDNConversion==='FORCE')
2248
+			if ($_tryIDNConversion === 'FORCE')
2249 2249
 			{
2250 2250
 				//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_string.'='.Horde_Idna::decode($_string));
2251 2251
 				$_string = Horde_Idna::decode($_string);
@@ -2261,17 +2261,17 @@  discard block
 block discarded – undo
2261 2261
 	 * @param  boolean $decode try decoding
2262 2262
 	 * @return mixed - based on the input type
2263 2263
 	 */
2264
-	function decode_subject($_string,$decode=true)
2264
+	function decode_subject($_string, $decode = true)
2265 2265
 	{
2266 2266
 		#$string = $_string;
2267
-		if($_string=='NIL')
2267
+		if ($_string == 'NIL')
2268 2268
 		{
2269 2269
 			return 'No Subject';
2270 2270
 		}
2271 2271
 		if ($decode) $_string = self::decode_header($_string);
2272 2272
 		// make sure its utf-8
2273 2273
 		$test = @json_encode($_string);
2274
-		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2274
+		if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2275 2275
 		{
2276 2276
 			$_string = utf8_encode($_string);
2277 2277
 		}
@@ -2323,18 +2323,18 @@  discard block
 block discarded – undo
2323 2323
 	function createFolder($_parent, $_folderName, &$_error)
2324 2324
 	{
2325 2325
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2326
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2327
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2326
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2327
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2328 2328
 
2329
-		if(empty($parent)) {
2329
+		if (empty($parent)) {
2330 2330
 			$newFolderName = $folderName;
2331 2331
 		} else {
2332 2332
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2333
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2333
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2334 2334
 		}
2335 2335
 		if (empty($newFolderName)) return false;
2336 2336
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2337
-		if ($this->folderExists($newFolderName,true))
2337
+		if ($this->folderExists($newFolderName, true))
2338 2338
 		{
2339 2339
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2340 2340
 			return $newFolderName;
@@ -2351,7 +2351,7 @@  discard block
 block discarded – undo
2351 2351
 		}
2352 2352
 		catch (\Exception $e)
2353 2353
 		{
2354
-			$_error = lang('Could not create Folder %1 Reason: %2',$newFolderName,$e->getMessage());
2354
+			$_error = lang('Could not create Folder %1 Reason: %2', $newFolderName, $e->getMessage());
2355 2355
 			error_log(__METHOD__.' ('.__LINE__.') '.' create Folder '.$newFolderName.'->'.$e->getMessage().' ('.$e->details.') Namespace:'.array2string($this->icServer->getNameSpaces()).function_backtrace());
2356 2356
 			return false;
2357 2357
 		}
@@ -2380,15 +2380,15 @@  discard block
 block discarded – undo
2380 2380
 	 */
2381 2381
 	function renameFolder($_oldFolderName, $_parent, $_folderName)
2382 2382
 	{
2383
-		$oldFolderName	= $_oldFolderName;//$this->_encodeFolderName($_oldFolderName);
2384
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2385
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2383
+		$oldFolderName = $_oldFolderName; //$this->_encodeFolderName($_oldFolderName);
2384
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2385
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2386 2386
 
2387
-		if(empty($parent)) {
2387
+		if (empty($parent)) {
2388 2388
 			$newFolderName = $folderName;
2389 2389
 		} else {
2390 2390
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2391
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2391
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2392 2392
 		}
2393 2393
 		if (self::$debug) error_log("create folder: $newFolderName");
2394 2394
 		try
@@ -2397,10 +2397,10 @@  discard block
 block discarded – undo
2397 2397
 		}
2398 2398
 		catch (\Exception $e)
2399 2399
 		{
2400
-			throw new Exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage());;
2400
+			throw new Exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage()); ;
2401 2401
 		}
2402 2402
 		// clear FolderExistsInfoCache
2403
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2403
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2404 2404
 
2405 2405
 		return $newFolderName;
2406 2406
 
@@ -2419,15 +2419,15 @@  discard block
 block discarded – undo
2419 2419
 		//$folderName = $this->_encodeFolderName($_folderName);
2420 2420
 		try
2421 2421
 		{
2422
-			$this->icServer->subscribeMailbox($_folderName,false);
2422
+			$this->icServer->subscribeMailbox($_folderName, false);
2423 2423
 			$this->icServer->deleteMailbox($_folderName);
2424 2424
 		}
2425 2425
 		catch (\Exception $e)
2426 2426
 		{
2427
-			throw new Exception("Deleting Folder $_folderName failed! Error:".$e->getMessage());;
2427
+			throw new Exception("Deleting Folder $_folderName failed! Error:".$e->getMessage()); ;
2428 2428
 		}
2429 2429
 		// clear FolderExistsInfoCache
2430
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2430
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2431 2431
 
2432 2432
 		return true;
2433 2433
 	}
@@ -2462,10 +2462,10 @@  discard block
 block discarded – undo
2462 2462
 	 *
2463 2463
 	 * @return array with folder objects. eg.: INBOX => {inbox object}
2464 2464
 	 */
2465
-	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2465
+	function getFolderObjects($_subscribedOnly = false, $_getCounters = false, $_alwaysGetDefaultFolders = false, $_useCacheIfPossible = true)
2466 2466
 	{
2467 2467
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2468
-		if (self::$debugTimes) $starttime = microtime (true);
2468
+		if (self::$debugTimes) $starttime = microtime(true);
2469 2469
 		static $folders2return;
2470 2470
 		//$_subscribedOnly=false;
2471 2471
 		// always use static on single request if info is available;
@@ -2473,42 +2473,42 @@  discard block
 block discarded – undo
2473 2473
 		// set $_useCacheIfPossible to false !
2474 2474
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2475 2475
 		{
2476
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2476
+			if (self::$debugTimes) self::logRunTimes($starttime, null, 'using static', __METHOD__.' ('.__LINE__.') ');
2477 2477
 			return $folders2return[$this->icServer->ImapServerId];
2478 2478
 		}
2479 2479
 
2480
-		if ($_subscribedOnly && $_getCounters===false)
2480
+		if ($_subscribedOnly && $_getCounters === false)
2481 2481
 		{
2482
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2482
+			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
2483 2483
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2484 2484
 			{
2485 2485
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2486
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2486
+				if (self::$debugTimes) self::logRunTimes($starttime, null, 'from Cache', __METHOD__.' ('.__LINE__.') ');
2487 2487
 				return $folders2return[$this->icServer->ImapServerId];
2488 2488
 			}
2489 2489
 		}
2490 2490
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2491 2491
 		static $folderBasicInfo;
2492
-		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId])) $folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2492
+		if (is_null($folderBasicInfo) || !isset($folderBasicInfo[$this->icServer->ImapServerId])) $folderBasicInfo = Cache::getCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
2493 2493
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2494 2494
 
2495 2495
 		$delimiter = $this->getHierarchyDelimiter();
2496 2496
 
2497 2497
 		$inboxData = new \stdClass;
2498
-		$inboxData->name 		= 'INBOX';
2498
+		$inboxData->name = 'INBOX';
2499 2499
 		$inboxData->folderName		= 'INBOX';
2500
-		$inboxData->displayName		= lang('INBOX');
2500
+		$inboxData->displayName = lang('INBOX');
2501 2501
 		$inboxData->delimiter 		= $delimiter;
2502
-		$inboxData->shortFolderName	= 'INBOX';
2503
-		$inboxData->shortDisplayName	= lang('INBOX');
2502
+		$inboxData->shortFolderName = 'INBOX';
2503
+		$inboxData->shortDisplayName = lang('INBOX');
2504 2504
 		$inboxData->subscribed = true;
2505
-		if($_getCounters == true) {
2505
+		if ($_getCounters == true) {
2506 2506
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2507 2507
 		}
2508 2508
 		// force unsubscribed by preference showAllFoldersInFolderPane
2509 2509
 		if ($_subscribedOnly == true &&
2510 2510
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2511
-			$this->mailPreferences['showAllFoldersInFolderPane']==1)
2511
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1)
2512 2512
 		{
2513 2513
 			$_subscribedOnly = false;
2514 2514
 		}
@@ -2521,12 +2521,12 @@  discard block
 block discarded – undo
2521 2521
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2522 2522
 		if (is_array($nameSpace))
2523 2523
 		{
2524
-			foreach($nameSpace as $k => $singleNameSpace) {
2524
+			foreach ($nameSpace as $k => $singleNameSpace) {
2525 2525
 				$type = $singleNameSpace['type'];
2526 2526
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2527
-				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2527
+				$foldersNameSpace[$type]['delimiter'] = $singleNameSpace['delimiter'];
2528 2528
 
2529
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
2529
+				if (is_array($singleNameSpace) && $fetchedAllInOneGo == false) {
2530 2530
 					// fetch and sort the subscribed folders
2531 2531
 					// we alway fetch the subscribed, as this provides the only way to tell
2532 2532
 					// if a folder is subscribed or not
@@ -2534,22 +2534,22 @@  discard block
 block discarded – undo
2534 2534
 					{
2535 2535
 						try
2536 2536
 						{
2537
-							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('',0,true);
2537
+							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('', 0, true);
2538 2538
 							if (!empty($subscribedMailboxes))
2539 2539
 							{
2540 2540
 								$fetchedAllInOneGo = true;
2541 2541
 							}
2542 2542
 							else
2543 2543
 							{
2544
-								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'],0,true);
2544
+								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'], 0, true);
2545 2545
 							}
2546 2546
 						}
2547
-						catch(Exception $e)
2547
+						catch (Exception $e)
2548 2548
 						{
2549 2549
 							continue;
2550 2550
 						}
2551 2551
 						//echo "subscribedMailboxes";_debug_array($subscribedMailboxes);
2552
-						$subscribedFoldersPerNS = (!empty($subscribedMailboxes)?array_keys($subscribedMailboxes):array());
2552
+						$subscribedFoldersPerNS = (!empty($subscribedMailboxes) ? array_keys($subscribedMailboxes) : array());
2553 2553
 						//if (is_array($foldersNameSpace[$type]['subscribed'])) sort($foldersNameSpace[$type]['subscribed']);
2554 2554
 						//_debug_array($foldersNameSpace);
2555 2555
 						//error_log(__METHOD__.__LINE__.array2string($singleNameSpace).':#:'.array2string($subscribedFoldersPerNS));
@@ -2559,18 +2559,18 @@  discard block
 block discarded – undo
2559 2559
 							foreach ($subscribedMailboxes as $k => $finfo)
2560 2560
 							{
2561 2561
 								//error_log(__METHOD__.__LINE__.$k.':#:'.array2string($finfo));
2562
-								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k]=
2563
-								$folderBasicInfo[$this->icServer->ImapServerId][$k]=array(
2562
+								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k] =
2563
+								$folderBasicInfo[$this->icServer->ImapServerId][$k] = array(
2564 2564
 									'MAILBOX'=>$finfo['MAILBOX'],
2565 2565
 									'ATTRIBUTES'=>$finfo['ATTRIBUTES'],
2566
-									'delimiter'=>$finfo['delimiter'],//lowercase for some reason???
2567
-									'SUBSCRIBED'=>$finfo['SUBSCRIBED'],//seeded by getMailboxes
2566
+									'delimiter'=>$finfo['delimiter'], //lowercase for some reason???
2567
+									'SUBSCRIBED'=>$finfo['SUBSCRIBED'], //seeded by getMailboxes
2568 2568
 								);
2569
-								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k,$foldersNameSpace[$type]['subscribed']))
2569
+								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k, $foldersNameSpace[$type]['subscribed']))
2570 2570
 								{
2571 2571
 									$foldersNameSpace[$type]['subscribed'][] = $k;
2572 2572
 								}
2573
-								if (empty($foldersNameSpace[$type]['all']) || !in_array($k,$foldersNameSpace[$type]['all']))
2573
+								if (empty($foldersNameSpace[$type]['all']) || !in_array($k, $foldersNameSpace[$type]['all']))
2574 2574
 								{
2575 2575
 									$foldersNameSpace[$type]['all'][] = $k;
2576 2576
 								}
@@ -2593,7 +2593,7 @@  discard block
 block discarded – undo
2593 2593
 						// that may produce problems, when encountering recursions probably
2594 2594
 						// horde is handling that, so we do not; keep that in mind!
2595 2595
 						//$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],2,true);
2596
-						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],0,true);
2596
+						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'], 0, true);
2597 2597
 					}
2598 2598
 					catch (\Exception $e)
2599 2599
 					{
@@ -2611,26 +2611,26 @@  discard block
 block discarded – undo
2611 2611
 					foreach ($allMailboxesExt as $mbx) {
2612 2612
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2613 2613
 						{
2614
-							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
2614
+							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']] = array(
2615 2615
 								'MAILBOX'=>$mbx['MAILBOX'],
2616 2616
 								'ATTRIBUTES'=>$mbx['ATTRIBUTES'],
2617
-								'delimiter'=>$mbx['delimiter'],//lowercase for some reason???
2618
-								'SUBSCRIBED'=>$mbx['SUBSCRIBED'],//seeded by getMailboxes
2617
+								'delimiter'=>$mbx['delimiter'], //lowercase for some reason???
2618
+								'SUBSCRIBED'=>$mbx['SUBSCRIBED'], //seeded by getMailboxes
2619 2619
 							);
2620 2620
 							if ($mbx['SUBSCRIBED'] && !isset($subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2621 2621
 							{
2622 2622
 								$subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']] = $folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']];
2623 2623
 							}
2624 2624
 						}
2625
-						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'],$foldersNameSpace[$type]['subscribed'])))
2625
+						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'], $foldersNameSpace[$type]['subscribed'])))
2626 2626
 						{
2627 2627
 							$foldersNameSpace[$type]['subscribed'][] = $mbx['MAILBOX'];
2628 2628
 						}
2629 2629
 						//echo __METHOD__;_debug_array($mbx);
2630 2630
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
2631
-						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2632
-							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2633
-							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2631
+						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']]) ||
2632
+							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']]) ||
2633
+							(substr($mbx['MAILBOX'], -1) == $foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'], 0, -1)]))
2634 2634
 						) continue;
2635 2635
 
2636 2636
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
@@ -2640,7 +2640,7 @@  discard block
 block discarded – undo
2640 2640
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2641 2641
 					$allMailboxes = array();
2642 2642
 					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2643
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2643
+						if (!in_array($mbx['MAILBOX'], $allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2644 2644
 						//echo "Result:";_debug_array($allMailboxes);
2645 2645
 					}
2646 2646
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
@@ -2649,57 +2649,57 @@  discard block
 block discarded – undo
2649 2649
 			}
2650 2650
 		}
2651 2651
 		//subscribed folders may be used in getFolderStatus
2652
-		Cache::setCache(Cache::INSTANCE,'email','subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$subscribedFoldersForCache,$expiration=60*60*1);
2652
+		Cache::setCache(Cache::INSTANCE, 'email', 'subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']), $subscribedFoldersForCache, $expiration = 60 * 60 * 1);
2653 2653
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2654 2654
 		$autoFolderObjects = $folders = array();
2655 2655
 		$autofolder_exists = array();
2656
-		foreach( array('personal', 'others', 'shared') as $type) {
2657
-			if(isset($foldersNameSpace[$type])) {
2658
-				if($_subscribedOnly) {
2659
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2656
+		foreach (array('personal', 'others', 'shared') as $type) {
2657
+			if (isset($foldersNameSpace[$type])) {
2658
+				if ($_subscribedOnly) {
2659
+					if (!empty($foldersNameSpace[$type]['subscribed'])) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2660 2660
 				} else {
2661
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2661
+					if (!empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2662 2662
 				}
2663
-				foreach((array)$listOfFolders as $folderName) {
2663
+				foreach ((array)$listOfFolders as $folderName) {
2664 2664
 					//echo "<br>FolderToCheck:$folderName<br>";
2665 2665
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2666
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2667
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2666
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue; //when subscribedonly, we fetch all folders in one go.
2667
+					if ($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all']) || in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2668 2668
 						#echo "$folderName failed to be here <br>";
2669 2669
 						continue;
2670 2670
 					}
2671 2671
 					if (isset($folders[$folderName])) continue;
2672 2672
 					if (isset($autoFolderObjects[$folderName])) continue;
2673
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2673
+					if (empty($delimiter) || $delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2674 2674
 					$folderParts = explode($delimiter, $folderName);
2675 2675
 					$shortName = array_pop($folderParts);
2676 2676
 
2677 2677
 					$folderObject = new \stdClass;
2678
-					$folderObject->delimiter	= $delimiter;
2679
-					$folderObject->folderName	= $folderName;
2680
-					$folderObject->shortFolderName	= $shortName;
2681
-					if(!$_subscribedOnly) {
2678
+					$folderObject->delimiter = $delimiter;
2679
+					$folderObject->folderName = $folderName;
2680
+					$folderObject->shortFolderName = $shortName;
2681
+					if (!$_subscribedOnly) {
2682 2682
 						#echo $folderName."->".$type."<br>";
2683 2683
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2684 2684
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2685 2685
 					}
2686 2686
 
2687
-					if($_getCounters == true) {
2687
+					if ($_getCounters == true) {
2688 2688
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2689 2689
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2690 2690
 					}
2691
-					if(strtoupper($folderName) == 'INBOX') {
2691
+					if (strtoupper($folderName) == 'INBOX') {
2692 2692
 						$folderName = 'INBOX';
2693
-						$folderObject->folderName	= 'INBOX';
2694
-						$folderObject->shortFolderName	= 'INBOX';
2695
-						$folderObject->displayName	= lang('INBOX');
2693
+						$folderObject->folderName = 'INBOX';
2694
+						$folderObject->shortFolderName = 'INBOX';
2695
+						$folderObject->displayName = lang('INBOX');
2696 2696
 						$folderObject->shortDisplayName = lang('INBOX');
2697
-						$folderObject->subscribed	= true;
2697
+						$folderObject->subscribed = true;
2698 2698
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2699
-					} elseif (in_array($shortName,self::$autoFolders)) {
2700
-						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2699
+					} elseif (in_array($shortName, self::$autoFolders)) {
2700
+						$tmpfolderparts = explode($delimiter, $folderObject->folderName);
2701 2701
 						array_pop($tmpfolderparts);
2702
-						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2702
+						$folderObject->displayName = implode($delimiter, $tmpfolderparts).$delimiter.lang($shortName);
2703 2703
 						$folderObject->shortDisplayName = lang($shortName);
2704 2704
 						unset($tmpfolderparts);
2705 2705
 					} else {
@@ -2707,13 +2707,13 @@  discard block
 block discarded – undo
2707 2707
 						$folderObject->shortDisplayName = $shortName;
2708 2708
 					}
2709 2709
 					//$folderName = $folderName;
2710
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
2710
+					if (in_array($shortName, self::$autoFolders) && self::searchValueInFolderObjects($shortName, $autoFolderObjects) === false) {
2711 2711
 						$autoFolderObjects[$folderName] = $folderObject;
2712 2712
 					} else {
2713 2713
 						$folders[$folderName] = $folderObject;
2714 2714
 					}
2715 2715
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2716
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
2716
+					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders();
2717 2717
 					if (isset(self::$specialUseFolders[$folderName]))
2718 2718
 					{
2719 2719
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2722,27 +2722,27 @@  discard block
 block discarded – undo
2722 2722
 			}
2723 2723
 		}
2724 2724
 		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
2725
-			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2725
+			uasort($autoFolderObjects, array($this, "sortByAutoFolderPos"));
2726 2726
 		}
2727 2727
 		// check if some standard folders are missing and need to be created
2728 2728
 		if (count($autofolder_exists) < count(self::$autoFolders) && $this->check_create_autofolders($autofolder_exists))
2729 2729
 		{
2730 2730
 			// if new folders have been created, re-read folders ignoring the cache
2731
-			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2731
+			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false); // false = do NOT use cache
2732 2732
 		}
2733
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
2733
+		if (is_array($folders)) uasort($folders, array($this, "sortByDisplayName"));
2734 2734
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2735 2735
 		//_debug_array($folders2return); #exit;
2736
-		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
2737
-		if (($_subscribedOnly && $_getCounters===false) ||
2738
-			($_subscribedOnly == false && $_getCounters===false &&
2736
+		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject, (array)$autoFolderObjects, (array)$folders);
2737
+		if (($_subscribedOnly && $_getCounters === false) ||
2738
+			($_subscribedOnly == false && $_getCounters === false &&
2739 2739
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2740
-			$this->mailPreferences['showAllFoldersInFolderPane']==1))
2740
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1))
2741 2741
 		{
2742
-			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2742
+			Cache::setCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), $folders2return, $expiration = 60 * 60 * 1);
2743 2743
 		}
2744
-		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2745
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
2744
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderBasicInfo, $expiration = 60 * 60 * 1);
2745
+		if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') ');
2746 2746
 		return $folders2return[$this->icServer->ImapServerId];
2747 2747
 	}
2748 2748
 
@@ -2763,21 +2763,21 @@  discard block
 block discarded – undo
2763 2763
 	 *
2764 2764
 	 * @return array arrays of folders
2765 2765
 	 */
2766
-	function getFolderArrays ($_nodePath = null, $_onlyTopLevel = false, $_search= 2, $_subscribedOnly = false, $_getCounter = false)
2766
+	function getFolderArrays($_nodePath = null, $_onlyTopLevel = false, $_search = 2, $_subscribedOnly = false, $_getCounter = false)
2767 2767
 	{
2768 2768
 		// delimiter
2769 2769
 		$delimiter = $this->getHierarchyDelimiter();
2770 2770
 
2771
-		$folders = $nameSpace =  array();
2771
+		$folders = $nameSpace = array();
2772 2772
 		$nameSpaceTmp = $this->_getNameSpaces();
2773
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
2774
-			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2773
+		foreach ($nameSpaceTmp as $k => $singleNameSpace) {
2774
+			$nameSpace[$singleNameSpace['type']] = $singleNameSpace;
2775 2775
 		}
2776 2776
 		unset($nameSpaceTmp);
2777 2777
 
2778 2778
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2779 2779
 		// Get special use folders
2780
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
2780
+		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders(); // Set self::$specialUseFolders
2781 2781
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2782 2782
 		if ($_onlyTopLevel) // top level leaves
2783 2783
 		{
@@ -2788,20 +2788,20 @@  discard block
 block discarded – undo
2788 2788
 			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
2789 2789
 			if (self::$mailConfig['examineNamespace'])
2790 2790
 			{
2791
-				$prefixes=array();
2791
+				$prefixes = array();
2792 2792
 				if (is_array($nameSpace))
2793 2793
 				{
2794
-					foreach($nameSpace as $k => $singleNameSpace) {
2794
+					foreach ($nameSpace as $k => $singleNameSpace) {
2795 2795
 						$type = $singleNameSpace['type'];
2796 2796
 
2797
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
2797
+						if (is_array($singleNameSpace) && $singleNameSpace['prefix']) {
2798 2798
 							$prefixes[$type] = $singleNameSpace['prefix'];
2799 2799
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2800
-							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
2800
+							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search == 0 ? 0 : 2, true);
2801 2801
 							if (is_array($result))
2802 2802
 							{
2803 2803
 								ksort($result);
2804
-								$topFolders = array_merge($topFolders,$result);
2804
+								$topFolders = array_merge($topFolders, $result);
2805 2805
 							}
2806 2806
 						}
2807 2807
 					}
@@ -2810,7 +2810,7 @@  discard block
 block discarded – undo
2810 2810
 
2811 2811
 			$autofolders = array();
2812 2812
 
2813
-			foreach(self::$specialUseFolders as $path => $folder)
2813
+			foreach (self::$specialUseFolders as $path => $folder)
2814 2814
 			{
2815 2815
 				if ($this->folderExists($path))
2816 2816
 				{
@@ -2818,9 +2818,9 @@  discard block
 block discarded – undo
2818 2818
 				}
2819 2819
 			}
2820 2820
 			// Check if the special use folders are there, otherwise try to create them
2821
-			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders ($autofolders))
2821
+			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders($autofolders))
2822 2822
 			{
2823
-				return $this->getFolderArrays ($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2823
+				return $this->getFolderArrays($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2824 2824
 			}
2825 2825
 
2826 2826
 			// now process topFolders for next level
@@ -2828,13 +2828,13 @@  discard block
 block discarded – undo
2828 2828
 			{
2829 2829
 				$pattern = "/\\".$delimiter."/";
2830 2830
 				$reference = preg_replace($pattern, '', $node['MAILBOX']);
2831
-				if(!empty($prefixes))
2831
+				if (!empty($prefixes))
2832 2832
 				{
2833 2833
 					$reference = '';
2834
-					$tmpArray = explode($delimiter,$node['MAILBOX']);
2835
-					foreach($tmpArray as $p)
2834
+					$tmpArray = explode($delimiter, $node['MAILBOX']);
2835
+					foreach ($tmpArray as $p)
2836 2836
 					{
2837
-						$reference = empty($reference)?$p:$reference.$delimiter.$p;
2837
+						$reference = empty($reference) ? $p : $reference.$delimiter.$p;
2838 2838
 					}
2839 2839
 				}
2840 2840
 				$mainFolder = $subFolders = array();
@@ -2870,19 +2870,19 @@  discard block
 block discarded – undo
2870 2870
 							$nFolders [$path] = $folder;
2871 2871
 						}
2872 2872
 					}
2873
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
2873
+					if (is_array($aFolders)) uasort($aFolders, array($this, 'sortByAutofolder'));
2874 2874
 					//ksort($aFolders);
2875 2875
 
2876 2876
 					// Sort none auto folders base on mailbox name
2877
-					uasort($nFolders,array($this,'sortByMailbox'));
2877
+					uasort($nFolders, array($this, 'sortByMailbox'));
2878 2878
 
2879
-					$subFolders = array_merge($aFolders,$nFolders);
2879
+					$subFolders = array_merge($aFolders, $nFolders);
2880 2880
 				}
2881 2881
 				else
2882 2882
 				{
2883 2883
 					if (is_array($subFolders)) ksort($subFolders);
2884 2884
 				}
2885
-				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2885
+				$folders = array_merge($folders, (array)$mainFolder, (array)$subFolders);
2886 2886
 			}
2887 2887
 		}
2888 2888
 		elseif ($_nodePath) // single node
@@ -2909,9 +2909,9 @@  discard block
 block discarded – undo
2909 2909
 				$folders = $this->icServer->getMailboxes($path, $_search, true);
2910 2910
 			}
2911 2911
 
2912
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2912
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
2913 2913
 		}
2914
-		elseif(!$_nodePath) // all
2914
+		elseif (!$_nodePath) // all
2915 2915
 		{
2916 2916
 			if ($_subscribedOnly)
2917 2917
 			{
@@ -2927,101 +2927,101 @@  discard block
 block discarded – undo
2927 2927
 		{
2928 2928
 			// SORTING FOLDERS
2929 2929
 			//self::$debugTimes=true;
2930
-			if (self::$debugTimes) $starttime = microtime (true);
2930
+			if (self::$debugTimes) $starttime = microtime(true);
2931 2931
 			// Merge of all auto folders and specialusefolders
2932 2932
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
2933
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2933
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
2934 2934
 			$tmpFolders = $folders;
2935
-			$inboxFolderObject=$inboxSubFolderObjects=$autoFolderObjects=$typeFolderObject=$mySpecialUseFolders=array();
2936
-			$googleMailFolderObject=$googleAutoFolderObjects=$googleSubFolderObjects=array();
2937
-			$isGoogleMail=false;
2938
-			foreach($autoFoldersTmp as $afk=>$aF)
2935
+			$inboxFolderObject = $inboxSubFolderObjects = $autoFolderObjects = $typeFolderObject = $mySpecialUseFolders = array();
2936
+			$googleMailFolderObject = $googleAutoFolderObjects = $googleSubFolderObjects = array();
2937
+			$isGoogleMail = false;
2938
+			foreach ($autoFoldersTmp as $afk=>$aF)
2939 2939
 			{
2940
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
2940
+				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF] = $this->getFolderByType($aF, false);
2941 2941
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2942 2942
 			}
2943 2943
 			//error_log(array2string($mySpecialUseFolders));
2944 2944
 			foreach ($tmpFolders as $k => $f) {
2945
-				$sorted=false;
2946
-				if (strtoupper(substr($k,0,5))=='INBOX') {
2947
-					if (strtoupper($k)=='INBOX') {
2945
+				$sorted = false;
2946
+				if (strtoupper(substr($k, 0, 5)) == 'INBOX') {
2947
+					if (strtoupper($k) == 'INBOX') {
2948 2948
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
2949
-						$inboxFolderObject[$k]=$f;
2949
+						$inboxFolderObject[$k] = $f;
2950 2950
 						unset($folders[$k]);
2951
-						$sorted=true;
2951
+						$sorted = true;
2952 2952
 					} else {
2953
-						$isAutoFolder=false;
2954
-						foreach($autoFoldersTmp as $afk=>$aF)
2953
+						$isAutoFolder = false;
2954
+						foreach ($autoFoldersTmp as $afk=>$aF)
2955 2955
 						{
2956 2956
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2957
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2958
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
2959
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
2957
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2958
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
2959
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
2960 2960
 							{
2961 2961
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
2962
-								$isAutoFolder=true;
2963
-								$autoFolderObjects[$k]=$f;
2962
+								$isAutoFolder = true;
2963
+								$autoFolderObjects[$k] = $f;
2964 2964
 								break;
2965 2965
 							}
2966 2966
 						}
2967
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
2967
+						if ($isAutoFolder == false) $inboxSubFolderObjects[$k] = $f;
2968 2968
 						unset($folders[$k]);
2969
-						$sorted=true;
2969
+						$sorted = true;
2970 2970
 					}
2971
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
2972
-					$isGoogleMail=true;
2973
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
2974
-						$googleMailFolderObject[$k]=$f;
2971
+				} elseif (strtoupper(substr($k, 0, 13)) == '[GOOGLE MAIL]') {
2972
+					$isGoogleMail = true;
2973
+					if (strtoupper($k) == '[GOOGLE MAIL]') {
2974
+						$googleMailFolderObject[$k] = $f;
2975 2975
 						unset($folders[$k]);
2976
-						$sorted=true;
2976
+						$sorted = true;
2977 2977
 					} else {
2978
-						$isAutoFolder=false;
2979
-						foreach($autoFoldersTmp as $afk=>$aF)
2978
+						$isAutoFolder = false;
2979
+						foreach ($autoFoldersTmp as $afk=>$aF)
2980 2980
 						{
2981 2981
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2982
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2983
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
2984
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
2982
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2983
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
2984
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
2985 2985
 							{
2986 2986
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
2987
-								$isAutoFolder=true;
2988
-								$googleAutoFolderObjects[$k]=$f;
2987
+								$isAutoFolder = true;
2988
+								$googleAutoFolderObjects[$k] = $f;
2989 2989
 								break;
2990 2990
 							}
2991 2991
 						}
2992
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
2992
+						if ($isAutoFolder == false) $googleSubFolderObjects[$k] = $f;
2993 2993
 						unset($folders[$k]);
2994
-						$sorted=true;
2994
+						$sorted = true;
2995 2995
 					}
2996 2996
 				} else {
2997
-					$isAutoFolder=false;
2998
-					foreach($autoFoldersTmp as $afk=>$aF)
2997
+					$isAutoFolder = false;
2998
+					foreach ($autoFoldersTmp as $afk=>$aF)
2999 2999
 					{
3000 3000
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3001
-						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3002
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3003
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3001
+						if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3002
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3003
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3004 3004
 						{
3005 3005
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3006
-							$isAutoFolder=true;
3007
-							$autoFolderObjects[$k]=$f;
3006
+							$isAutoFolder = true;
3007
+							$autoFolderObjects[$k] = $f;
3008 3008
 							unset($folders[$k]);
3009
-							$sorted=true;
3009
+							$sorted = true;
3010 3010
 							break;
3011 3011
 						}
3012 3012
 					}
3013 3013
 				}
3014 3014
 
3015
-				if ($sorted==false)
3015
+				if ($sorted == false)
3016 3016
 				{
3017
-					foreach(array('others','shared') as $type)
3017
+					foreach (array('others', 'shared') as $type)
3018 3018
 					{
3019
-						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3019
+						if ($nameSpace[$type]['prefix_present'] && $nameSpace[$type]['prefix'])
3020 3020
 						{
3021
-							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3022
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3021
+							if (substr($k, 0, strlen($nameSpace[$type]['prefix'])) == $nameSpace[$type]['prefix'] ||
3022
+								substr($k, 0, strlen($nameSpace[$type]['prefix']) - strlen($nameSpace[$type]['delimiter'])) == substr($nameSpace[$type]['prefix'], 0, strlen($nameSpace[$type]['delimiter']) * -1)) {
3023 3023
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3024
-								$typeFolderObject[$type][$k]=$f;
3024
+								$typeFolderObject[$type][$k] = $f;
3025 3025
 								unset($folders[$k]);
3026 3026
 							}
3027 3027
 						}
@@ -3032,40 +3032,40 @@  discard block
 block discarded – undo
3032 3032
 			// avoid calling sortByAutoFolder as it is not regarding subfolders
3033 3033
 			$autoFolderObjectsTmp = $autoFolderObjects;
3034 3034
 			unset($autoFolderObjects);
3035
-			uasort($autoFolderObjectsTmp, array($this,'sortByMailbox'));
3036
-			foreach($autoFoldersTmp as $afk=>$aF)
3035
+			uasort($autoFolderObjectsTmp, array($this, 'sortByMailbox'));
3036
+			foreach ($autoFoldersTmp as $afk=>$aF)
3037 3037
 			{
3038
-				foreach($autoFolderObjectsTmp as $k => $f)
3038
+				foreach ($autoFolderObjectsTmp as $k => $f)
3039 3039
 				{
3040
-					if($aF && ($mySpecialUseFolders[$aF]==$k ||
3041
-						substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter ||
3042
-						stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3040
+					if ($aF && ($mySpecialUseFolders[$aF] == $k ||
3041
+						substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter ||
3042
+						stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false))
3043 3043
 					{
3044
-						$autoFolderObjects[$k]=$f;
3044
+						$autoFolderObjects[$k] = $f;
3045 3045
 					}
3046 3046
 				}
3047 3047
 			}
3048 3048
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3049 3049
 			if (!$isGoogleMail) {
3050
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3050
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$inboxSubFolderObjects, (array)$folders, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
3051 3051
 			} else {
3052 3052
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3053 3053
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3054 3054
 				unset($googleAutoFolderObjects);
3055
-				uasort($gAutoFolderObjectsTmp, array($this,'sortByMailbox'));
3056
-				foreach($autoFoldersTmp as $afk=>$aF)
3055
+				uasort($gAutoFolderObjectsTmp, array($this, 'sortByMailbox'));
3056
+				foreach ($autoFoldersTmp as $afk=>$aF)
3057 3057
 				{
3058
-					foreach($gAutoFolderObjectsTmp as $k => $f)
3058
+					foreach ($gAutoFolderObjectsTmp as $k => $f)
3059 3059
 					{
3060
-						if($aF && ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter))
3060
+						if ($aF && ($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter))
3061 3061
 						{
3062
-							$googleAutoFolderObjects[$k]=$f;
3062
+							$googleAutoFolderObjects[$k] = $f;
3063 3063
 						}
3064 3064
 					}
3065 3065
 				}
3066
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3066
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$folders, (array)$googleMailFolderObject, $googleAutoFolderObjects, $googleSubFolderObjects, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
3067 3067
 			}
3068
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3068
+			if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') Sorting:');
3069 3069
 			//self::$debugTimes=false;
3070 3070
 		}
3071 3071
 		// Get counter information and add them to each fetched folders array
@@ -3087,10 +3087,10 @@  discard block
 block discarded – undo
3087 3087
 	 * @param array $autofolders_exists existing folders, no need to check their existance again
3088 3088
 	 * @return int number of new folders created
3089 3089
 	 */
3090
-	function check_create_autofolders(array $autofolders_exists=array())
3090
+	function check_create_autofolders(array $autofolders_exists = array())
3091 3091
 	{
3092 3092
 		$num_created = 0;
3093
-		foreach(self::$autoFolders as $folder)
3093
+		foreach (self::$autoFolders as $folder)
3094 3094
 		{
3095 3095
 			$created = false;
3096 3096
 			if (!in_array($folder, $autofolders_exists) && $this->_getSpecialUseFolder($folder, true, $created) &&
@@ -3115,7 +3115,7 @@  discard block
 block discarded – undo
3115 3115
 		$rv = false;
3116 3116
 		foreach ($haystack as $k => $v)
3117 3117
 		{
3118
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3118
+			foreach ($v as &$sv) {if (trim($sv) == trim($needle)) return $k; }
3119 3119
 		}
3120 3120
 		return $rv;
3121 3121
 	}
@@ -3128,9 +3128,9 @@  discard block
 block discarded – undo
3128 3128
 	 * @param array $b array of folders
3129 3129
 	 * @return int expect values (0, 1 or -1)
3130 3130
 	 */
3131
-	function sortByMailbox($a,$b)
3131
+	function sortByMailbox($a, $b)
3132 3132
 	{
3133
-		return strcasecmp($a['MAILBOX'],$b['MAILBOX']);
3133
+		return strcasecmp($a['MAILBOX'], $b['MAILBOX']);
3134 3134
 	}
3135 3135
 
3136 3136
 	/**
@@ -3140,13 +3140,13 @@  discard block
 block discarded – undo
3140 3140
 	 * @param string $_hDelimiter hierarchy delimiter
3141 3141
 	 * @return array returns an array of data extracted from given node path
3142 3142
 	 */
3143
-	static function pathToFolderData ($_path, $_hDelimiter)
3143
+	static function pathToFolderData($_path, $_hDelimiter)
3144 3144
 	{
3145 3145
 		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3146 3146
 		list(,$path) = explode(self::DELIMITER, $_path);
3147 3147
 		$path_chain = $parts = explode($_hDelimiter, $path);
3148 3148
 		$name = array_pop($parts);
3149
-		return array (
3149
+		return array(
3150 3150
 			'name' => $name,
3151 3151
 			'mailbox' => $path,
3152 3152
 			'parent' => implode($_hDelimiter, $parts),
@@ -3169,8 +3169,8 @@  discard block
 block discarded – undo
3169 3169
 		// 0, 1 und -1
3170 3170
 		$a = self::pathToFolderData($_a['MAILBOX'], $_a['delimiter']);
3171 3171
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3172
-		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3173
-		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3172
+		$pos1 = array_search(trim($a['name']), self::$autoFolders);
3173
+		$pos2 = array_search(trim($b['name']), self::$autoFolders);
3174 3174
 		if ($pos1 == $pos2) return 0;
3175 3175
 		return ($pos1 < $pos2) ? -1 : 1;
3176 3176
 	}
@@ -3183,10 +3183,10 @@  discard block
 block discarded – undo
3183 3183
 	 * @param object $b array of folderobjects
3184 3184
 	 * @return int expect values (0, 1 or -1)
3185 3185
 	 */
3186
-	function sortByDisplayName($a,$b)
3186
+	function sortByDisplayName($a, $b)
3187 3187
 	{
3188 3188
 		// 0, 1 und -1
3189
-		return strcasecmp($a->displayName,$b->displayName);
3189
+		return strcasecmp($a->displayName, $b->displayName);
3190 3190
 	}
3191 3191
 
3192 3192
 	/**
@@ -3197,11 +3197,11 @@  discard block
 block discarded – undo
3197 3197
 	 * @param object $b array of folderobjects
3198 3198
 	 * @return int expect values (0, 1 or -1)
3199 3199
 	 */
3200
-	function sortByAutoFolderPos($a,$b)
3200
+	function sortByAutoFolderPos($a, $b)
3201 3201
 	{
3202 3202
 		// 0, 1 und -1
3203
-		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3204
-		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3203
+		$pos1 = array_search(trim($a->shortFolderName), self::$autoFolders);
3204
+		$pos2 = array_search(trim($b->shortFolderName), self::$autoFolders);
3205 3205
 		if ($pos1 == $pos2) return 0;
3206 3206
 		return ($pos1 < $pos2) ? -1 : 1;
3207 3207
 	}
@@ -3214,7 +3214,7 @@  discard block
 block discarded – undo
3214 3214
 	 * @param boolean $_returnObject return the counters as object rather than an array
3215 3215
 	 * @return mixed false or array of counters array(MESSAGES,UNSEEN,RECENT,UIDNEXT,UIDVALIDITY) or object
3216 3216
 	 */
3217
-	function getMailBoxCounters($folderName,$_returnObject=true)
3217
+	function getMailBoxCounters($folderName, $_returnObject = true)
3218 3218
 	{
3219 3219
 		try
3220 3220
 		{
@@ -3226,9 +3226,9 @@  discard block
 block discarded – undo
3226 3226
 			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3227 3227
 			return false;
3228 3228
 		}
3229
-		if(is_array($folderStatus)) {
3230
-			if ($_returnObject===false) return $folderStatus;
3231
-			$status =  new \stdClass;
3229
+		if (is_array($folderStatus)) {
3230
+			if ($_returnObject === false) return $folderStatus;
3231
+			$status = new \stdClass;
3232 3232
 			$status->messages   = $folderStatus['MESSAGES'];
3233 3233
 			$status->unseen     = $folderStatus['UNSEEN'];
3234 3234
 			$status->recent     = $folderStatus['RECENT'];
@@ -3250,42 +3250,42 @@  discard block
 block discarded – undo
3250 3250
 	 * @param string $reclevel 0, counter to keep track of the current recursionlevel
3251 3251
 	 * @return array of mailboxes
3252 3252
 	 */
3253
-	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
3253
+	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel = 0)
3254 3254
 	{
3255 3255
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3256
-		$maxreclevel=25;
3256
+		$maxreclevel = 25;
3257 3257
 		if ($reclevel > $maxreclevel) {
3258
-			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3258
+			error_log(__METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3259 3259
 			return array();
3260 3260
 		}
3261 3261
 		$reclevel++;
3262 3262
 		// clean up double delimiters
3263
-		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$_mailbox);
3263
+		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $_mailbox);
3264 3264
 		//get that mailbox in question
3265
-		$mbx = $this->icServer->getMailboxes($_mailbox,1,true);
3265
+		$mbx = $this->icServer->getMailboxes($_mailbox, 1, true);
3266 3266
 		$mbxkeys = array_keys($mbx);
3267 3267
 		#_debug_array($mbx);
3268 3268
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3269 3269
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3270 3270
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3271
-		if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) {
3271
+		if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren', $mbx[$mbxkeys[0]]["ATTRIBUTES"]))) {
3272 3272
 			// if there are children fetch them
3273 3273
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3274 3274
 
3275
-			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '':$delimiter),2,false);
3275
+			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '' : $delimiter), 2, false);
3276 3276
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3277 3277
 			//_debug_array($buff);
3278 3278
 			$allMailboxes = array();
3279 3279
 			foreach ($buff as $mbxname) {
3280 3280
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3281
-				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3281
+				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $mbxname['MAILBOX']);
3282 3282
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
3283
-				if ( $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix  && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3283
+				if ($mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3284 3284
 				{
3285 3285
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3286 3286
 				}
3287 3287
 			}
3288
-			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3288
+			if (!(in_array('\NoSelect', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect', $mbx[$mbxkeys[0]]["ATTRIBUTES"]))) $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3289 3289
 			return $allMailboxes;
3290 3290
 		} else {
3291 3291
 			return array($_mailbox);
@@ -3300,18 +3300,18 @@  discard block
 block discarded – undo
3300 3300
 	 * @param boolean& $created =null on return true: if folder was just created, false if not
3301 3301
 	 * @return mixed string or false
3302 3302
 	 */
3303
-	function _getSpecialUseFolder($_type, $_checkexistance=TRUE, &$created=null)
3303
+	function _getSpecialUseFolder($_type, $_checkexistance = TRUE, &$created = null)
3304 3304
 	{
3305 3305
 		static $types = array(
3306
-			'Drafts'   => array('profileKey'=>'acc_folder_draft','autoFolderName'=>'Drafts'),
3307
-			'Template' => array('profileKey'=>'acc_folder_template','autoFolderName'=>'Templates'),
3308
-			'Trash'    => array('profileKey'=>'acc_folder_trash','autoFolderName'=>'Trash'),
3309
-			'Sent'     => array('profileKey'=>'acc_folder_sent','autoFolderName'=>'Sent'),
3310
-			'Junk'     => array('profileKey'=>'acc_folder_junk','autoFolderName'=>'Junk'),
3311
-			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3312
-			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3306
+			'Drafts'   => array('profileKey'=>'acc_folder_draft', 'autoFolderName'=>'Drafts'),
3307
+			'Template' => array('profileKey'=>'acc_folder_template', 'autoFolderName'=>'Templates'),
3308
+			'Trash'    => array('profileKey'=>'acc_folder_trash', 'autoFolderName'=>'Trash'),
3309
+			'Sent'     => array('profileKey'=>'acc_folder_sent', 'autoFolderName'=>'Sent'),
3310
+			'Junk'     => array('profileKey'=>'acc_folder_junk', 'autoFolderName'=>'Junk'),
3311
+			'Outbox'   => array('profileKey'=>'acc_folder_outbox', 'autoFolderName'=>'Outbox'),
3312
+			'Archive'   => array('profileKey'=>'acc_folder_archive', 'autoFolderName'=>'Archive'),
3313 3313
 		);
3314
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3314
+		if ($_type == 'Templates') $_type = 'Template'; // for some reason self::$autofolders uses 'Templates'!
3315 3315
 		$created = false;
3316 3316
 		if (!isset($types[$_type]))
3317 3317
 		{
@@ -3333,7 +3333,7 @@  discard block
 block discarded – undo
3333 3333
 		}
3334 3334
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3335 3335
 		if ($_type == 'Archive') {
3336
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3336
+			if ($_folderName && $_checkexistance && strtolower($_folderName) != 'none' && !$this->folderExists($_folderName, true)) {
3337 3337
 				return false;
3338 3338
 			} else {
3339 3339
 				return $_folderName;
@@ -3341,38 +3341,38 @@  discard block
 block discarded – undo
3341 3341
 
3342 3342
 		}
3343 3343
 		// does the folder exist??? (is configured/preset, but non-existent)
3344
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3344
+		if ($_folderName && $_checkexistance && strtolower($_folderName) != 'none' && !$this->folderExists($_folderName, true)) {
3345 3345
 			try
3346 3346
 			{
3347 3347
 				$error = null;
3348 3348
 				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3349 3349
 				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3350 3350
 			}
3351
-			catch(Exception $e)
3351
+			catch (Exception $e)
3352 3352
 			{
3353 3353
 				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage().':'.function_backtrace());
3354 3354
 				$_folderName = false;
3355 3355
 			}
3356 3356
 		}
3357 3357
 		// not sure yet if false is the correct behavior on none
3358
-		if ($_folderName =='none') return 'none' ; //false;
3358
+		if ($_folderName == 'none') return 'none'; //false;
3359 3359
 		//no (valid) folder found yet; try specialUseFolders
3360
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
3360
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type, self::$specialUseFolders))) $_folderName = $f;
3361 3361
 		//no specialUseFolder; try some Defaults
3362 3362
 		if (empty($_folderName) && isset($types[$_type]))
3363 3363
 		{
3364 3364
 			$nameSpace = $this->_getNameSpaces();
3365
-			$prefix='';
3365
+			$prefix = '';
3366 3366
 			foreach ($nameSpace as $nSp)
3367 3367
 			{
3368
-				if ($nSp['type']=='personal')
3368
+				if ($nSp['type'] == 'personal')
3369 3369
 				{
3370 3370
 					//error_log(__METHOD__.__LINE__.array2string($nSp));
3371 3371
 					$prefix = $nSp['prefix'];
3372 3372
 					break;
3373 3373
 				}
3374 3374
 			}
3375
-			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'],true))
3375
+			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'], true))
3376 3376
 			{
3377 3377
 				$_folderName = $prefix.$types[$_type]['autoFolderName'];
3378 3378
 			}
@@ -3381,11 +3381,11 @@  discard block
 block discarded – undo
3381 3381
 				try
3382 3382
 				{
3383 3383
 					$error = null;
3384
-					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3384
+					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'], $error);
3385 3385
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3386 3386
 					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3387 3387
 				}
3388
-				catch(Exception $e)
3388
+				catch (Exception $e)
3389 3389
 				{
3390 3390
 					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage());
3391 3391
 					$_folderName = false;
@@ -3401,7 +3401,7 @@  discard block
 block discarded – undo
3401 3401
 	 * @param boolean $_checkexistance trigger check for existance
3402 3402
 	 * @return mixed string or false
3403 3403
 	 */
3404
-	function getFolderByType($type, $_checkexistance=false)
3404
+	function getFolderByType($type, $_checkexistance = false)
3405 3405
 	{
3406 3406
 		return $this->_getSpecialUseFolder($type, $_checkexistance);
3407 3407
 	}
@@ -3411,7 +3411,7 @@  discard block
 block discarded – undo
3411 3411
 	 * @param boolean $_checkexistance trigger check for existance
3412 3412
 	 * @return mixed string or false
3413 3413
 	 */
3414
-	function getJunkFolder($_checkexistance=TRUE)
3414
+	function getJunkFolder($_checkexistance = TRUE)
3415 3415
 	{
3416 3416
 		return $this->_getSpecialUseFolder('Junk', $_checkexistance);
3417 3417
 	}
@@ -3421,7 +3421,7 @@  discard block
 block discarded – undo
3421 3421
 	 * @param boolean $_checkexistance trigger check for existance
3422 3422
 	 * @return mixed string or false
3423 3423
 	 */
3424
-	function getDraftFolder($_checkexistance=TRUE)
3424
+	function getDraftFolder($_checkexistance = TRUE)
3425 3425
 	{
3426 3426
 		return $this->_getSpecialUseFolder('Drafts', $_checkexistance);
3427 3427
 	}
@@ -3431,7 +3431,7 @@  discard block
 block discarded – undo
3431 3431
 	 * @param boolean $_checkexistance trigger check for existance
3432 3432
 	 * @return mixed string or false
3433 3433
 	 */
3434
-	function getTemplateFolder($_checkexistance=TRUE)
3434
+	function getTemplateFolder($_checkexistance = TRUE)
3435 3435
 	{
3436 3436
 		return $this->_getSpecialUseFolder('Template', $_checkexistance);
3437 3437
 	}
@@ -3441,7 +3441,7 @@  discard block
 block discarded – undo
3441 3441
 	 * @param boolean $_checkexistance trigger check for existance
3442 3442
 	 * @return mixed string or false
3443 3443
 	 */
3444
-	function getTrashFolder($_checkexistance=TRUE)
3444
+	function getTrashFolder($_checkexistance = TRUE)
3445 3445
 	{
3446 3446
 		return $this->_getSpecialUseFolder('Trash', $_checkexistance);
3447 3447
 	}
@@ -3451,7 +3451,7 @@  discard block
 block discarded – undo
3451 3451
 	 * @param boolean $_checkexistance trigger check for existance
3452 3452
 	 * @return mixed string or false
3453 3453
 	 */
3454
-	function getSentFolder($_checkexistance=TRUE)
3454
+	function getSentFolder($_checkexistance = TRUE)
3455 3455
 	{
3456 3456
 		return $this->_getSpecialUseFolder('Sent', $_checkexistance);
3457 3457
 	}
@@ -3461,7 +3461,7 @@  discard block
 block discarded – undo
3461 3461
 	 * @param boolean $_checkexistance trigger check for existance
3462 3462
 	 * @return mixed string or false
3463 3463
 	 */
3464
-	function getOutboxFolder($_checkexistance=TRUE)
3464
+	function getOutboxFolder($_checkexistance = TRUE)
3465 3465
 	{
3466 3466
 		return $this->_getSpecialUseFolder('Outbox', $_checkexistance);
3467 3467
 	}
@@ -3471,7 +3471,7 @@  discard block
 block discarded – undo
3471 3471
 	 * @param boolean $_checkexistance trigger check for existance . We do no autocreation for configured Archive folder
3472 3472
 	 * @return mixed string or false
3473 3473
 	 */
3474
-	function getArchiveFolder($_checkexistance=TRUE)
3474
+	function getArchiveFolder($_checkexistance = TRUE)
3475 3475
 	{
3476 3476
 		return $this->_getSpecialUseFolder('Archive', $_checkexistance);
3477 3477
 	}
@@ -3482,10 +3482,10 @@  discard block
 block discarded – undo
3482 3482
 	 * @param boolean $_checkexistance trigger check for existance
3483 3483
 	 * @return boolean
3484 3484
 	 */
3485
-	function isSentFolder($_folderName, $_checkexistance=TRUE)
3485
+	function isSentFolder($_folderName, $_checkexistance = TRUE)
3486 3486
 	{
3487 3487
 		$sentFolder = $this->getSentFolder($_checkexistance);
3488
-		if(empty($sentFolder)) {
3488
+		if (empty($sentFolder)) {
3489 3489
 			return false;
3490 3490
 		}
3491 3491
 		// does the folder exist???
@@ -3493,7 +3493,7 @@  discard block
 block discarded – undo
3493 3493
 			return false;
3494 3494
 		}
3495 3495
 
3496
-		if(false !== stripos($_folderName, $sentFolder)) {
3496
+		if (false !== stripos($_folderName, $sentFolder)) {
3497 3497
 			return true;
3498 3498
 		} else {
3499 3499
 			return false;
@@ -3506,15 +3506,15 @@  discard block
 block discarded – undo
3506 3506
 	 * @param boolean $_checkexistance trigger check for existance
3507 3507
 	 * @return boolean
3508 3508
 	 */
3509
-	function isOutbox($_folderName, $_checkexistance=TRUE)
3509
+	function isOutbox($_folderName, $_checkexistance = TRUE)
3510 3510
 	{
3511
-		if (stripos($_folderName, 'Outbox')===false) {
3511
+		if (stripos($_folderName, 'Outbox') === false) {
3512 3512
 			return false;
3513 3513
 		}
3514 3514
 		// does the folder exist???
3515 3515
 		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
3516 3516
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3517
-			if(false !== stripos($_folderName, $outboxFolder)) {
3517
+			if (false !== stripos($_folderName, $outboxFolder)) {
3518 3518
 				return true;
3519 3519
 			} else {
3520 3520
 				return false;
@@ -3529,18 +3529,18 @@  discard block
 block discarded – undo
3529 3529
 	 * @param boolean $_checkexistance trigger check for existance
3530 3530
 	 * @return boolean
3531 3531
 	 */
3532
-	function isDraftFolder($_folderName, $_checkexistance=TRUE)
3532
+	function isDraftFolder($_folderName, $_checkexistance = TRUE)
3533 3533
 	{
3534 3534
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3535
-		if(empty($draftFolder)) {
3535
+		if (empty($draftFolder)) {
3536 3536
 			return false;
3537 3537
 		}
3538 3538
 		// does the folder exist???
3539 3539
 		if ($_checkexistance && !$this->folderExists($_folderName)) {
3540 3540
 			return false;
3541 3541
 		}
3542
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3543
-		if(false !== stripos($_folderName, $draftFolder)) {
3542
+		if (is_a($_folderName, "Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3543
+		if (false !== stripos($_folderName, $draftFolder)) {
3544 3544
 			return true;
3545 3545
 		} else {
3546 3546
 			return false;
@@ -3553,10 +3553,10 @@  discard block
 block discarded – undo
3553 3553
 	 * @param boolean $_checkexistance trigger check for existance
3554 3554
 	 * @return boolean
3555 3555
 	 */
3556
-	function isTrashFolder($_folderName, $_checkexistance=TRUE)
3556
+	function isTrashFolder($_folderName, $_checkexistance = TRUE)
3557 3557
 	{
3558 3558
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3559
-		if(empty($trashFolder)) {
3559
+		if (empty($trashFolder)) {
3560 3560
 			return false;
3561 3561
 		}
3562 3562
 		// does the folder exist???
@@ -3564,7 +3564,7 @@  discard block
 block discarded – undo
3564 3564
 			return false;
3565 3565
 		}
3566 3566
 
3567
-		if(false !== stripos($_folderName, $trashFolder)) {
3567
+		if (false !== stripos($_folderName, $trashFolder)) {
3568 3568
 			return true;
3569 3569
 		} else {
3570 3570
 			return false;
@@ -3577,10 +3577,10 @@  discard block
 block discarded – undo
3577 3577
 	 * @param boolean $_checkexistance trigger check for existance
3578 3578
 	 * @return boolean
3579 3579
 	 */
3580
-	function isTemplateFolder($_folderName, $_checkexistance=TRUE)
3580
+	function isTemplateFolder($_folderName, $_checkexistance = TRUE)
3581 3581
 	{
3582 3582
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3583
-		if(empty($templateFolder)) {
3583
+		if (empty($templateFolder)) {
3584 3584
 			return false;
3585 3585
 		}
3586 3586
 		// does the folder exist???
@@ -3588,7 +3588,7 @@  discard block
 block discarded – undo
3588 3588
 			return false;
3589 3589
 		}
3590 3590
 
3591
-		if(false !== stripos($_folderName, $templateFolder)) {
3591
+		if (false !== stripos($_folderName, $templateFolder)) {
3592 3592
 			return true;
3593 3593
 		} else {
3594 3594
 			return false;
@@ -3601,24 +3601,24 @@  discard block
 block discarded – undo
3601 3601
 	 * @param boolean $_forceCheck trigger check for existance on icServer
3602 3602
 	 * @return mixed string or false
3603 3603
 	 */
3604
-	function folderExists($_folder, $_forceCheck=false)
3604
+	function folderExists($_folder, $_forceCheck = false)
3605 3605
 	{
3606 3606
 		static $folderInfo;
3607 3607
 		$forceCheck = $_forceCheck;
3608 3608
 		if (empty($_folder))
3609 3609
 		{
3610 3610
 			// this error is more or less without significance, unless we force the check
3611
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3611
+			if ($_forceCheck === true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3612 3612
 			return false;
3613 3613
 		}
3614 3614
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3615
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3616
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
3615
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox") && $_forceCheck === false) return true;
3616
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox")) $_folder = $_folder->utf8;
3617 3617
 		// reduce traffic within the Instance per User; Expire every 5 hours
3618 3618
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3619
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
3619
+		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), $expiration = 60 * 60 * 5);
3620 3620
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3621
-		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3621
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck === false)
3622 3622
 		{
3623 3623
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Using cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID);
3624 3624
 			return $folderInfo[$this->profileID][$_folder];
@@ -3634,7 +3634,7 @@  discard block
 block discarded – undo
3634 3634
 
3635 3635
 		// does the folder exist???
3636 3636
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3637
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3637
+		if ($forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3638 3638
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3639 3639
 			//return false;
3640 3640
 			//try to connect
@@ -3650,12 +3650,12 @@  discard block
 block discarded – undo
3650 3650
 		}
3651 3651
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Folder Exists:'.$folderInfo[$this->profileID][$_folder].function_backtrace());
3652 3652
 
3653
-		if(!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3653
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3654 3654
 			$folderInfo[$this->profileID][$_folder] !== true)
3655 3655
 		{
3656 3656
 			$folderInfo[$this->profileID][$_folder] = false; // set to false, whatever it was (to have a valid returnvalue for the static return)
3657 3657
 		}
3658
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,$expiration=60*60*5);
3658
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, $expiration = 60 * 60 * 5);
3659 3659
 		return (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) ? $folderInfo[$this->profileID][$_folder] : false);
3660 3660
 	}
3661 3661
 
@@ -3668,14 +3668,14 @@  discard block
 block discarded – undo
3668 3668
 	 */
3669 3669
 	function compressFolder($_folderName = false)
3670 3670
 	{
3671
-		$folderName	= ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3672
-		$deleteOptions	= $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3673
-		$trashFolder	= $this->getTrashFolder();
3671
+		$folderName = ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3672
+		$deleteOptions = $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3673
+		$trashFolder = $this->getTrashFolder();
3674 3674
 
3675 3675
 		$this->icServer->openMailbox($folderName);
3676 3676
 
3677
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3678
-			$this->deleteMessages('all',$folderName,'remove_immediately');
3677
+		if (strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3678
+			$this->deleteMessages('all', $folderName, 'remove_immediately');
3679 3679
 		} else {
3680 3680
 			$this->icServer->expunge($folderName);
3681 3681
 		}
@@ -3691,19 +3691,19 @@  discard block
 block discarded – undo
3691 3691
 	 * @return bool true, as we do not handle return values yet
3692 3692
 	 * @throws Exception
3693 3693
 	 */
3694
-	function deleteMessages($_messageUID, $_folder=NULL, $_forceDeleteMethod='no')
3694
+	function deleteMessages($_messageUID, $_folder = NULL, $_forceDeleteMethod = 'no')
3695 3695
 	{
3696 3696
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3697 3697
 		$oldMailbox = '';
3698 3698
 		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
3699 3699
 		if (empty($_messageUID))
3700 3700
 		{
3701
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
3701
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
3702 3702
 			return false;
3703 3703
 		}
3704
-		elseif ($_messageUID==='all')
3704
+		elseif ($_messageUID === 'all')
3705 3705
 		{
3706
-			$_messageUID= null;
3706
+			$_messageUID = null;
3707 3707
 		}
3708 3708
 		else
3709 3709
 		{
@@ -3712,32 +3712,32 @@  discard block
 block discarded – undo
3712 3712
 			$uidsToDelete->add($_messageUID);
3713 3713
 		}
3714 3714
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3715
-		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately"))) $deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
3715
+		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod, array('move_to_trash', "mark_as_deleted", "remove_immediately"))) $deleteOptions = ($this->mailPreferences['deleteOptions'] ? $this->mailPreferences['deleteOptions'] : "mark_as_deleted");
3716 3716
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3717 3717
 		$trashFolder    = $this->getTrashFolder();
3718
-		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3718
+		$draftFolder = $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3719 3719
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3720
-		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3720
+		if ((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3721 3721
 		   (strtolower($_folder) == strtolower($draftFolder))) {
3722 3722
 			$deleteOptions = "remove_immediately";
3723 3723
 		}
3724
-		if($this->icServer->getCurrentMailbox() != $_folder) {
3724
+		if ($this->icServer->getCurrentMailbox() != $_folder) {
3725 3725
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3726 3726
 			$this->icServer->openMailbox($_folder);
3727 3727
 		}
3728 3728
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3729 3729
 		$updateCache = false;
3730
-		switch($deleteOptions) {
3730
+		switch ($deleteOptions) {
3731 3731
 			case "move_to_trash":
3732 3732
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3733 3733
 				$updateCache = true;
3734
-				if(!empty($trashFolder)) {
3734
+				if (!empty($trashFolder)) {
3735 3735
 					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3736
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
3736
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ".$this->sessionData['mailbox']);
3737 3737
 					// copy messages
3738 3738
 					try
3739 3739
 					{
3740
-						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete,'move'=>true));
3740
+						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete, 'move'=>true));
3741 3741
 					}
3742 3742
 					catch (\Exception $e)
3743 3743
 					{
@@ -3749,18 +3749,18 @@  discard block
 block discarded – undo
3749 3749
 			case "mark_as_deleted":
3750 3750
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3751 3751
 				// mark messages as deleted
3752
-				if (is_null($_messageUID)) $_messageUID='all';
3753
-				foreach((array)$_messageUID as $key =>$uid)
3752
+				if (is_null($_messageUID)) $_messageUID = 'all';
3753
+				foreach ((array)$_messageUID as $key =>$uid)
3754 3754
 				{
3755 3755
 					//flag messages, that are flagged for deletion as seen too
3756 3756
 					$this->flagMessages('read', $uid, $_folder);
3757 3757
 					$flags = $this->getFlags($uid);
3758 3758
 					$this->flagMessages('delete', $uid, $_folder);
3759 3759
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3760
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
3760
+					if (strpos(array2string($flags), 'Deleted') !== false) $undelete[] = $uid;
3761 3761
 					unset($flags);
3762 3762
 				}
3763
-				foreach((array)$undelete as $key =>$uid)
3763
+				foreach ((array)$undelete as $key =>$uid)
3764 3764
 				{
3765 3765
 					$this->flagMessages('undelete', $uid, $_folder);
3766 3766
 				}
@@ -3769,14 +3769,14 @@  discard block
 block discarded – undo
3769 3769
 			case "remove_immediately":
3770 3770
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3771 3771
 				$updateCache = true;
3772
-				if (is_null($_messageUID)) $_messageUID='all';
3772
+				if (is_null($_messageUID)) $_messageUID = 'all';
3773 3773
 				if (is_object($_messageUID))
3774 3774
 				{
3775 3775
 					$this->flagMessages('delete', $_messageUID, $_folder);
3776 3776
 				}
3777 3777
 				else
3778 3778
 				{
3779
-					foreach((array)$_messageUID as $key =>$uid)
3779
+					foreach ((array)$_messageUID as $key =>$uid)
3780 3780
 					{
3781 3781
 						//flag messages, that are flagged for deletion as seen too
3782 3782
 						$this->flagMessages('delete', $uid, $_folder);
@@ -3786,7 +3786,7 @@  discard block
 block discarded – undo
3786 3786
 				$this->icServer->expunge($_folder);
3787 3787
 				break;
3788 3788
 		}
3789
-		if($oldMailbox != '') {
3789
+		if ($oldMailbox != '') {
3790 3790
 			$this->icServer->openMailbox($oldMailbox);
3791 3791
 		}
3792 3792
 
@@ -3800,7 +3800,7 @@  discard block
 block discarded – undo
3800 3800
 	 *
3801 3801
 	 * @return null/array flags
3802 3802
 	 */
3803
-	function getFlags ($_messageUID) {
3803
+	function getFlags($_messageUID) {
3804 3804
 		try
3805 3805
 		{
3806 3806
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -3813,7 +3813,7 @@  discard block
 block discarded – undo
3813 3813
 				'ids' => $uidsToFetch,
3814 3814
 			));
3815 3815
 			if (is_object($headersNew)) {
3816
-				foreach($headersNew->ids() as $id) {
3816
+				foreach ($headersNew->ids() as $id) {
3817 3817
 					$_headerObject = $headersNew->get($id);
3818 3818
 					$flags = $_headerObject->getFlags();
3819 3819
 				}
@@ -3836,22 +3836,22 @@  discard block
 block discarded – undo
3836 3836
 	 *
3837 3837
 	 * @return null/boolean
3838 3838
 	 */
3839
-	function getNotifyFlags ($_messageUID, $flags=null)
3839
+	function getNotifyFlags($_messageUID, $flags = null)
3840 3840
 	{
3841 3841
 		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
3842 3842
 		try
3843 3843
 		{
3844
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
3844
+			if ($flags === null) $flags = $this->getFlags($_messageUID);
3845 3845
 		}
3846 3846
 		catch (\Exception $e)
3847 3847
 		{
3848 3848
 			return null;
3849 3849
 		}
3850 3850
 
3851
-		if ( stripos( array2string($flags),'MDNSent')!==false)
3851
+		if (stripos(array2string($flags), 'MDNSent') !== false)
3852 3852
 			return true;
3853 3853
 
3854
-		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3854
+		if (stripos(array2string($flags), 'MDNnotSent') !== false)
3855 3855
 			return false;
3856 3856
 
3857 3857
 		return null;
@@ -3868,45 +3868,45 @@  discard block
 block discarded – undo
3868 3868
 	 *
3869 3869
 	 * @return bool true, as we do not handle icserver->setFlags returnValue
3870 3870
 	 */
3871
-	function flagMessages($_flag, $_messageUID,$_folder=NULL)
3871
+	function flagMessages($_flag, $_messageUID, $_folder = NULL)
3872 3872
 	{
3873 3873
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3874 3874
 		if (empty($_messageUID))
3875 3875
 		{
3876
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
3876
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
3877 3877
 			return false;
3878 3878
 		}
3879
-		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
3879
+		$this->icServer->openMailbox(($_folder ? $_folder : $this->sessionData['mailbox']));
3880 3880
 		$folder = $this->icServer->getCurrentMailbox();
3881
-		if (is_array($_messageUID)&& count($_messageUID)>50)
3881
+		if (is_array($_messageUID) && count($_messageUID) > 50)
3882 3882
 		{
3883
-			$count = $this->getMailBoxCounters($folder,true);
3884
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
3883
+			$count = $this->getMailBoxCounters($folder, true);
3884
+			if ($count->messages == count($_messageUID)) $_messageUID = 'all';
3885 3885
 		}
3886 3886
 
3887
-		if ($_messageUID==='all')
3887
+		if ($_messageUID === 'all')
3888 3888
 		{
3889 3889
 			$messageUIDs = array('all');
3890 3890
 		}
3891 3891
 		else
3892 3892
 		{
3893 3893
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
3894
-			$messageUIDs = array_chunk($_messageUID,50,true);
3894
+			$messageUIDs = array_chunk($_messageUID, 50, true);
3895 3895
 		}
3896 3896
 		try
3897 3897
 		{
3898
-			foreach($messageUIDs as &$uids)
3898
+			foreach ($messageUIDs as &$uids)
3899 3899
 			{
3900
-				if ($uids==='all')
3900
+				if ($uids === 'all')
3901 3901
 				{
3902
-					$uidsToModify=null;
3902
+					$uidsToModify = null;
3903 3903
 				}
3904 3904
 				else
3905 3905
 				{
3906 3906
 					$uidsToModify = new Horde_Imap_Client_Ids();
3907 3907
 					$uidsToModify->add($uids);
3908 3908
 				}
3909
-				switch($_flag) {
3909
+				switch ($_flag) {
3910 3910
 					case "delete":
3911 3911
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
3912 3912
 						break;
@@ -3930,7 +3930,7 @@  discard block
 block discarded – undo
3930 3930
 						break;
3931 3931
 					case "unread":
3932 3932
 					case "unseen":
3933
-						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen','\\Answered','$Forwarded'), 'ids'=> $uidsToModify));
3933
+						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen', '\\Answered', '$Forwarded'), 'ids'=> $uidsToModify));
3934 3934
 						break;
3935 3935
 					case "mdnsent":
3936 3936
 						$ret = $this->icServer->store($folder, array('add'=>array('MDNSent'), 'ids'=> $uidsToModify));
@@ -3988,13 +3988,13 @@  discard block
 block discarded – undo
3988 3988
 				}
3989 3989
 			}
3990 3990
 		}
3991
-		catch(Exception $e)
3991
+		catch (Exception $e)
3992 3992
 		{
3993 3993
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
3994 3994
 		}
3995 3995
 		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
3996 3996
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
3997
-		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
3997
+		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder) ? $_folder : $this->sessionData['mailbox'])]['uidValidity'] = 0;
3998 3998
 
3999 3999
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",".($_folder?$_folder:$this->sessionData['mailbox']));
4000 4000
 		return true; // as we do not catch/examine setFlags returnValue
@@ -4015,19 +4015,19 @@  discard block
 block discarded – undo
4015 4015
 	 * @return mixed/bool true,false or new uid
4016 4016
 	 * @throws Exception
4017 4017
 	 */
4018
-	function moveMessages($_foldername, $_messageUID, $deleteAfterMove=true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
4018
+	function moveMessages($_foldername, $_messageUID, $deleteAfterMove = true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
4019 4019
 	{
4020
-		$source = Mail\Account::read(($_sourceProfileID?$_sourceProfileID:$this->icServer->ImapServerId))->imapServer();
4020
+		$source = Mail\Account::read(($_sourceProfileID ? $_sourceProfileID : $this->icServer->ImapServerId))->imapServer();
4021 4021
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4022 4022
 		if (empty($_messageUID))
4023 4023
 		{
4024
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4024
+			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',', $_messageUID));
4025 4025
 			return false;
4026 4026
 		}
4027
-		elseif ($_messageUID==='all')
4027
+		elseif ($_messageUID === 'all')
4028 4028
 		{
4029 4029
 			//error_log(__METHOD__." all Message(s): ".implode(',',$_messageUID));
4030
-			$uidsToMove= null;
4030
+			$uidsToMove = null;
4031 4031
 		}
4032 4032
 		else
4033 4033
 		{
@@ -4036,7 +4036,7 @@  discard block
 block discarded – undo
4036 4036
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4037 4037
 			$uidsToMove->add($_messageUID);
4038 4038
 		}
4039
-		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
4039
+		$sourceFolder = (!empty($currentFolder) ? $currentFolder : $this->sessionData['mailbox']);
4040 4040
 		//error_log(__METHOD__.__LINE__."$_targetProfileID !== ".array2string($source->ImapServerId));
4041 4041
 		if (!is_null($_targetProfileID) && $_targetProfileID !== $source->ImapServerId)
4042 4042
 		{
@@ -4056,19 +4056,19 @@  discard block
 block discarded – undo
4056 4056
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4057 4057
 
4058 4058
 			if (is_object($headersNew)) {
4059
-				$c=0;
4059
+				$c = 0;
4060 4060
 				$retUid = new Horde_Imap_Client_Ids();
4061 4061
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4062 4062
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4063
-				foreach($headersNew as &$_headerObject) {
4063
+				foreach ($headersNew as &$_headerObject) {
4064 4064
 					$c++;
4065 4065
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4066 4066
 					$date = $_headerObject->getImapDate();
4067
-					$currentDate =  new Horde_Imap_Client_DateTime();
4067
+					$currentDate = new Horde_Imap_Client_DateTime();
4068 4068
 					// if the internal Date of the message equals the current date; try using the header date
4069
-					if ($date==$currentDate)
4069
+					if ($date == $currentDate)
4070 4070
 					{
4071
-						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
4071
+						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
4072 4072
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#'.$headerForPrio['DATE']);
4073 4073
 						$date = new Horde_Imap_Client_DateTime($headerForPrio['DATE']);
4074 4074
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#');
@@ -4077,20 +4077,20 @@  discard block
 block discarded – undo
4077 4077
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
4078 4078
 					$body = $_headerObject->getFullMsg();
4079 4079
 					$dataNflags[] = array('data'=>$body, 'flags'=>$flags, 'internaldate'=>$date);
4080
-					if ($c==1)
4080
+					if ($c == 1)
4081 4081
 					{
4082 4082
 						$target = Mail\Account::read($_targetProfileID)->imapServer();
4083 4083
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' TargetServer:'.$_targetProfileID.' TargetFolderObject:'.array2string($_foldername));
4084 4084
 						$foldername = $target->getMailbox($_foldername);
4085 4085
 						// make sure the target folder is open and ready
4086 4086
 						$target->openMailbox($foldername);
4087
-						$ret = $target->append($foldername,$dataNflags);
4087
+						$ret = $target->append($foldername, $dataNflags);
4088 4088
 						$retUid->add($ret);
4089 4089
 						unset($dataNflags);
4090 4090
 						// sleep 500 miliseconds; AS some sERVERs seem not to be capable of the load this is
4091 4091
 						// inflicting in them. they "reply" with an unspecific IMAP Error
4092
-						time_nanosleep(0,500000);
4093
-						$c=0;
4092
+						time_nanosleep(0, 500000);
4093
+						$c = 0;
4094 4094
 					}
4095 4095
 				}
4096 4096
 				if (isset($dataNflags))
@@ -4100,7 +4100,7 @@  discard block
 block discarded – undo
4100 4100
 					$foldername = $target->getMailbox($_foldername);
4101 4101
 					// make sure the target folder is open and ready
4102 4102
 					$target->openMailbox($foldername);
4103
-					$ret = $target->append($foldername,$dataNflags);
4103
+					$ret = $target->append($foldername, $dataNflags);
4104 4104
 					$retUid->add($ret);
4105 4105
 					unset($dataNflags);
4106 4106
 				}
@@ -4111,7 +4111,7 @@  discard block
 block discarded – undo
4111 4111
 				{
4112 4112
 					$remember = $this->icServer;
4113 4113
 					$this->icServer = $source;
4114
-					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod='remove_immediately');
4114
+					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod = 'remove_immediately');
4115 4115
 					$this->icServer = $remember;
4116 4116
 				}
4117 4117
 			}
@@ -4120,7 +4120,7 @@  discard block
 block discarded – undo
4120 4120
 		{
4121 4121
 			try
4122 4122
 			{
4123
-				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove,'move'=>$deleteAfterMove));
4123
+				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove, 'move'=>$deleteAfterMove));
4124 4124
 			}
4125 4125
 			catch (exception $e)
4126 4126
 			{
@@ -4140,19 +4140,19 @@  discard block
 block discarded – undo
4140 4140
 	 * @param string $format ='' if none is passed, use user prefs
4141 4141
 	 * @return string returns the date as it is parseable by strtotime, or current timestamp if everything fails
4142 4142
 	 */
4143
-	static function _strtotime($_date='', $format='', $convert2usertime=false)
4143
+	static function _strtotime($_date = '', $format = '', $convert2usertime = false)
4144 4144
 	{
4145 4145
 		try {
4146
-			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4147
-			if ($convert2usertime) $date->setUser();	// convert to user-time
4146
+			$date = new DateTime($_date); // parse date & time including timezone (throws exception, if not parsable)
4147
+			if ($convert2usertime) $date->setUser(); // convert to user-time
4148 4148
 			$date2return = $date->format($format);
4149 4149
 		}
4150
-		catch(\Exception $e)
4150
+		catch (\Exception $e)
4151 4151
 		{
4152
-			unset($e);	// not used
4152
+			unset($e); // not used
4153 4153
 
4154 4154
 			// remove last space-separated part and retry
4155
-			$parts = explode(' ',$_date);
4155
+			$parts = explode(' ', $_date);
4156 4156
 			if (count($parts) > 1)
4157 4157
 			{
4158 4158
 				array_pop($parts);
@@ -4173,12 +4173,12 @@  discard block
 block discarded – undo
4173 4173
 	 * @param mixed $_charset false or string -> Target charset, if false Mail displayCharset will be used
4174 4174
 	 * @return string
4175 4175
 	 */
4176
-	static function htmlentities($_string, $_charset=false)
4176
+	static function htmlentities($_string, $_charset = false)
4177 4177
 	{
4178 4178
 		//setting the charset (if not given)
4179
-		if ($_charset===false) $_charset = self::$displayCharset;
4179
+		if ($_charset === false) $_charset = self::$displayCharset;
4180 4180
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4181
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4181
+		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string, Translation::detect_encoding($_string), $_charset), ENT_QUOTES|ENT_IGNORE, $_charset, false);
4182 4182
 		return $string;
4183 4183
 	}
4184 4184
 
@@ -4195,21 +4195,21 @@  discard block
 block discarded – undo
4195 4195
 		//$_html = str_replace("\t",' ',$_html);
4196 4196
 		//error_log(__METHOD__.__LINE__.':'.$_html);
4197 4197
 		//repair doubleencoded ampersands, and some stuff htmLawed stumbles upon with balancing switched on
4198
-		$_html = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>','</td></font>','<br><td>','<tr></tr>','<o:p></o:p>','<o:p>','</o:p>'),
4199
-							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4198
+		$_html = str_replace(array('&amp;amp;', '<DIV><BR></DIV>', "<DIV>&nbsp;</DIV>", '<div>&nbsp;</div>', '</td></font>', '<br><td>', '<tr></tr>', '<o:p></o:p>', '<o:p>', '</o:p>'),
4199
+							 array('&amp;', '<BR>', '<BR>', '<BR>', '</font></td>', '<td>', '', '', '', ''), $_html);
4200 4200
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4201
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4202
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
4201
+		if (stripos($_html, 'style') !== false) Mail\Html::replaceTagsCompletley($_html, 'style'); // clean out empty or pagewide style definitions / left over tags
4202
+		if (stripos($_html, 'head') !== false) Mail\Html::replaceTagsCompletley($_html, 'head'); // Strip out stuff in head
4203 4203
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4204 4204
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4205 4205
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4206 4206
 
4207 4207
 		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
4208 4208
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4209
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4210
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4211
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4212
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
4209
+		if (stripos($_html, '!doctype') !== false) Mail\Html::replaceTagsCompletley($_html, '!doctype');
4210
+		if (stripos($_html, '?xml:namespace') !== false) Mail\Html::replaceTagsCompletley($_html, '\?xml:namespace', '/>', false);
4211
+		if (stripos($_html, '?xml version') !== false) Mail\Html::replaceTagsCompletley($_html, '\?xml version', '\?>', false);
4212
+		if (strpos($_html, '!CURSOR') !== false) Mail\Html::replaceTagsCompletley($_html, '!CURSOR');
4213 4213
 		// htmLawed filter only the 'body'
4214 4214
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4215 4215
 		//if ($matches[2])
@@ -4220,16 +4220,16 @@  discard block
 block discarded – undo
4220 4220
 		// purify got switched to htmLawed
4221 4221
 		// some testcode to test purifying / htmlawed
4222 4222
 		//$_html = "<BLOCKQUOTE>hi <div> there </div> kram <br> </blockquote>".$_html;
4223
-		$_html = Html\HtmLawed::purify($_html,self::$htmLawed_config,array(),true);
4223
+		$_html = Html\HtmLawed::purify($_html, self::$htmLawed_config, array(), true);
4224 4224
 		//if ($hasOther) $_html = $matches[1]. $_html. $matches[3];
4225 4225
 		// clean out comments , should not be needed as purify should do the job.
4226 4226
 		$search = array(
4227
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
4228
-			'@<!--[\s\S]*?[ \t\n\r]*-->@',         // Strip multi-line comments including CDATA
4227
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
4228
+			'@<!--[\s\S]*?[ \t\n\r]*-->@', // Strip multi-line comments including CDATA
4229 4229
 		);
4230
-		$_html = preg_replace($search,"",$_html);
4230
+		$_html = preg_replace($search, "", $_html);
4231 4231
 		// remove non printable chars
4232
-		$_html = preg_replace('/([\000-\011])/','',$_html);
4232
+		$_html = preg_replace('/([\000-\011])/', '', $_html);
4233 4233
 		//error_log(__METHOD__.':'.__LINE__.':'.$_html);
4234 4234
 	}
4235 4235
 
@@ -4246,12 +4246,12 @@  discard block
 block discarded – undo
4246 4246
 	function getMimePartCharset($_mimePartObject)
4247 4247
 	{
4248 4248
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4249
-		$CharsetFound=false;
4249
+		$CharsetFound = false;
4250 4250
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4251
-		if(is_array($_mimePartObject->parameters)) {
4252
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
4251
+		if (is_array($_mimePartObject->parameters)) {
4252
+			if (isset($_mimePartObject->parameters['CHARSET'])) {
4253 4253
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4254
-				$CharsetFound=true;
4254
+				$CharsetFound = true;
4255 4255
 			}
4256 4256
 		}
4257 4257
 		// this one is dirty, but until I find something that does the trick of detecting the encoding, ....
@@ -4270,7 +4270,7 @@  discard block
 block discarded – undo
4270 4270
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4271 4271
 	{
4272 4272
 		// decode the part
4273
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
4273
+		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage, true));
4274 4274
 		switch (strtoupper($_encoding))
4275 4275
 		{
4276 4276
 			case 'BASE64':
@@ -4310,10 +4310,10 @@  discard block
 block discarded – undo
4310 4310
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4311 4311
 		// as attachment AND as abstracted ical information (we use our notification style here).
4312 4312
 		$partText = $partCalendar = $partHTML = null;
4313
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
4313
+		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__, "LINE"=>__LINE__, "STRUCTURE"=>$_structure));
4314 4314
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4315 4315
 		$ignore_first_part = true;
4316
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4316
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4317 4317
 		{
4318 4318
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4319 4319
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4321,15 +4321,15 @@  discard block
 block discarded – undo
4321 4321
 			if ($ignore_first_part)
4322 4322
 			{
4323 4323
 				$ignore_first_part = false;
4324
-				continue;	// ignore multipart/alternative itself
4324
+				continue; // ignore multipart/alternative itself
4325 4325
 			}
4326 4326
 
4327 4327
 			$mimePart = $_structure->getPart($mime_id);
4328 4328
 
4329
-			switch($mimePart->getPrimaryType())
4329
+			switch ($mimePart->getPrimaryType())
4330 4330
 			{
4331 4331
 				case 'text':
4332
-					switch($mimePart->getSubType())
4332
+					switch ($mimePart->getSubType())
4333 4333
 					{
4334 4334
 						case 'plain':
4335 4335
 							if ($mimePart->getBytes() > 0) $partText = $mimePart;
@@ -4342,7 +4342,7 @@  discard block
 block discarded – undo
4342 4342
 					break;
4343 4343
 
4344 4344
 				case 'multipart':
4345
-					switch($mimePart->getSubType())
4345
+					switch ($mimePart->getSubType())
4346 4346
 					{
4347 4347
 						case 'related':
4348 4348
 						case 'mixed':
@@ -4364,13 +4364,13 @@  discard block
 block discarded – undo
4364 4364
 			}
4365 4365
 		}
4366 4366
 
4367
-		switch($_htmlMode)
4367
+		switch ($_htmlMode)
4368 4368
 		{
4369 4369
 			case 'html_only':
4370 4370
 			case 'always_display':
4371 4371
 				if ($partHTML)
4372 4372
 				{
4373
-					switch($partHTML->getSubType())
4373
+					switch ($partHTML->getSubType())
4374 4374
 					{
4375 4375
 						case 'related':
4376 4376
 							return $this->getMultipartRelated($_uid, $partHTML, $_htmlMode, $_preserveSeen);
@@ -4382,7 +4382,7 @@  discard block
 block discarded – undo
4382 4382
 							return $this->getTextPart($_uid, $partHTML, $_htmlMode, $_preserveSeen);
4383 4383
 					}
4384 4384
 				}
4385
-				elseif ($partText && $_htmlMode=='always_display')
4385
+				elseif ($partText && $_htmlMode == 'always_display')
4386 4386
 				{
4387 4387
 					return $this->getTextPart($_uid, $partText, $_htmlMode, $_preserveSeen);
4388 4388
 				}
@@ -4428,7 +4428,7 @@  discard block
 block discarded – undo
4428 4428
 	 * @param array	&$skipParts - passed by reference to have control/knowledge which parts are already fetched
4429 4429
 	 * @return array containing the desired part
4430 4430
 	 */
4431
-	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4431
+	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts = array())
4432 4432
 	{
4433 4433
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
4434 4434
 		$bodyPart = array();
@@ -4437,7 +4437,7 @@  discard block
 block discarded – undo
4437 4437
 		$ignore_first_part = true;
4438 4438
 		//$skipParts = array();
4439 4439
 		//error_log(__METHOD__.__LINE__.array2string($_structure->contentTypeMap()));
4440
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4440
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4441 4441
 		{
4442 4442
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4443 4443
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4445,9 +4445,9 @@  discard block
 block discarded – undo
4445 4445
 			{
4446 4446
 				$ignore_first_part = false;
4447 4447
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED FirstPart $mime_id: $mime_type");
4448
-				continue;	// ignore multipart/mixed itself
4448
+				continue; // ignore multipart/mixed itself
4449 4449
 			}
4450
-			if (array_key_exists($mime_id,$skipParts))
4450
+			if (array_key_exists($mime_id, $skipParts))
4451 4451
 			{
4452 4452
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED $mime_id: $mime_type");
4453 4453
 				continue;
@@ -4455,11 +4455,11 @@  discard block
 block discarded – undo
4455 4455
 
4456 4456
 			$part = $_structure->getPart($mime_id);
4457 4457
 
4458
-			switch($part->getPrimaryType())
4458
+			switch ($part->getPrimaryType())
4459 4459
 			{
4460 4460
 				case 'multipart':
4461 4461
 					if ($part->getDisposition() == 'attachment') continue;
4462
-					switch($part->getSubType())
4462
+					switch ($part->getSubType())
4463 4463
 					{
4464 4464
 						case 'alternative':
4465 4465
 							return array($this->getMultipartAlternative($_uid, $part, $_htmlMode, $_preserveSeen));
@@ -4475,15 +4475,15 @@  discard block
 block discarded – undo
4475 4475
 					}
4476 4476
 					break;
4477 4477
 				case 'application':
4478
-					switch($part->getSubType())
4478
+					switch ($part->getSubType())
4479 4479
 					{
4480 4480
 						case 'pgp-encrypted':
4481
-							if (($part = $_structure->getPart($mime_id+1)) &&
4481
+							if (($part = $_structure->getPart($mime_id + 1)) &&
4482 4482
 								$part->getType() == 'application/octet-stream')
4483 4483
 							{
4484 4484
 								$this->fetchPartContents($_uid, $part);
4485
-								$skipParts[$mime_id]=$mime_type;
4486
-								$skipParts[$mime_id+1]=$part->getType();
4485
+								$skipParts[$mime_id] = $mime_type;
4486
+								$skipParts[$mime_id + 1] = $part->getType();
4487 4487
 								$bodyPart[] = array(
4488 4488
 									'body'		=> $part->getContents(array(
4489 4489
 										'stream' => false,
@@ -4497,15 +4497,15 @@  discard block
 block discarded – undo
4497 4497
 					break;
4498 4498
 
4499 4499
 				case 'text':
4500
-					switch($part->getSubType())
4500
+					switch ($part->getSubType())
4501 4501
 					{
4502 4502
 						case 'plain':
4503 4503
 						case 'html':
4504 4504
 						case 'calendar': // inline ics/ical files
4505
-							if($part->getDisposition() != 'attachment')
4505
+							if ($part->getDisposition() != 'attachment')
4506 4506
 							{
4507 4507
 								$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4508
-								$skipParts[$mime_id]=$mime_type;
4508
+								$skipParts[$mime_id] = $mime_type;
4509 4509
 							}
4510 4510
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$part->type."/".$part->subType.' -> BodyPart:'.array2string($bodyPart[count($bodyPart)-1]));
4511 4511
 							break;
@@ -4514,16 +4514,16 @@  discard block
 block discarded – undo
4514 4514
 
4515 4515
 				case 'message':
4516 4516
 					//skip attachments
4517
-					if($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4517
+					if ($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4518 4518
 					{
4519 4519
 						$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4520
-						$skipParts[$mime_id]=$mime_type;
4520
+						$skipParts[$mime_id] = $mime_type;
4521 4521
 					}
4522 4522
 					// do not descend into attached Messages
4523
-					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4523
+					if ($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4524 4524
 					{
4525 4525
 						$skipParts[$mime_id.'.0'] = $mime_type;
4526
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
4526
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { $skipParts[$sub_id] = $sub_type; }
4527 4527
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4528 4528
 						//break 2;
4529 4529
 					}
@@ -4564,13 +4564,13 @@  discard block
 block discarded – undo
4564 4564
 	 * @param boolean $_tryDecodingServerside = true; wether to try to fetch Data with BINARY instead of BODY
4565 4565
 	 * @return string|resource
4566 4566
 	 */
4567
-	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4567
+	function getBodyPart($_uid, $_partID = null, $_folder = null, $_preserveSeen = false, $_stream = false, &$_encoding = null, $_tryDecodingServerside = true)
4568 4568
 	{
4569
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
4569
+		if (self::$debug) error_log(__METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
4570 4570
 
4571 4571
 		if (empty($_folder))
4572 4572
 		{
4573
-			$_folder = (isset($this->sessionData['mailbox'])&&$this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4573
+			$_folder = (isset($this->sessionData['mailbox']) && $this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4574 4574
 		}
4575 4575
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4576 4576
 		// querying contents of body part
@@ -4581,11 +4581,11 @@  discard block
 block discarded – undo
4581 4581
 		$fquery = new Horde_Imap_Client_Fetch_Query();
4582 4582
 		$fetchParams = array(
4583 4583
 			'peek' => $_preserveSeen,
4584
-			'decode' => true,	// try decode on server, does NOT neccessary work
4584
+			'decode' => true, // try decode on server, does NOT neccessary work
4585 4585
 		);
4586
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4586
+		if ($_tryDecodingServerside === false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4587 4587
 		{
4588
-			$_tryDecodingServerside=false;
4588
+			$_tryDecodingServerside = false;
4589 4589
 			$fetchParams = array(
4590 4590
 				'peek' => $_preserveSeen,
4591 4591
 			);
@@ -4605,12 +4605,12 @@  discard block
 block discarded – undo
4605 4605
 		}
4606 4606
 		// if we get an empty result, server may have trouble fetching data with UID FETCH $_uid (BINARY.PEEK[$_partID])
4607 4607
 		// thus we trigger a second go with UID FETCH $_uid (BODY.PEEK[$_partID])
4608
-		if (empty($partToReturn)&&$_tryDecodingServerside===true)
4608
+		if (empty($partToReturn) && $_tryDecodingServerside === true)
4609 4609
 		{
4610 4610
 			error_log(__METHOD__.__LINE__.' failed to fetch bodyPart in  BINARY. Try BODY');
4611 4611
 			$partToReturn = $this->getBodyPart($_uid, $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, false);
4612 4612
 		}
4613
-		return ($partToReturn?$partToReturn:null);
4613
+		return ($partToReturn ? $partToReturn : null);
4614 4614
 	}
4615 4615
 
4616 4616
 	/**
@@ -4623,13 +4623,13 @@  discard block
 block discarded – undo
4623 4623
 	 * @param boolean $_stream = false true return a stream, false return string
4624 4624
 	 * @return array containing the desired text part, mimeType and charset
4625 4625
 	 */
4626
-	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode='', $_preserveSeen=false, $_stream=false)
4626
+	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode = '', $_preserveSeen = false, $_stream = false)
4627 4627
 	{
4628 4628
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4629 4629
 		$bodyPart = array();
4630
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
4630
+		if (self::$debug) _debug_array(array($_structure, function_backtrace()));
4631 4631
 
4632
-		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4632
+		if ($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4633 4633
 		{
4634 4634
 			$bodyPart = array(
4635 4635
 				'error'		=> 1,
@@ -4675,10 +4675,10 @@  discard block
 block discarded – undo
4675 4675
 	 * @param string $_folder folder to work on
4676 4676
 	 * @return array containing the message body, mimeType and charset
4677 4677
 	 */
4678
-	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4678
+	function getMessageBody($_uid, $_htmlOptions = '', $_partID = null, Horde_Mime_Part $_structure = null, $_preserveSeen = false, $_folder = '')
4679 4679
 	{
4680 4680
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4681
-		if($_htmlOptions != '') {
4681
+		if ($_htmlOptions != '') {
4682 4682
 			$this->htmlOptions = $_htmlOptions;
4683 4683
 		}
4684 4684
 		if (empty($_folder))
@@ -4699,7 +4699,7 @@  discard block
 block discarded – undo
4699 4699
 			return array(
4700 4700
 				array(
4701 4701
 					'error'		=> 1,
4702
-					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions". 'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4702
+					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions".'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4703 4703
 					'mimeType'	=> 'text/plain',
4704 4704
 					'charSet'	=> self::$displayCharset,
4705 4705
 				)
@@ -4712,7 +4712,7 @@  discard block
 block discarded – undo
4712 4712
 			//_debug_array($_structure->getMimeId()); exit;
4713 4713
 		}
4714 4714
 
4715
-		switch($_structure->getPrimaryType())
4715
+		switch ($_structure->getPrimaryType())
4716 4716
 		{
4717 4717
 			case 'application':
4718 4718
 				return array(
@@ -4724,7 +4724,7 @@  discard block
 block discarded – undo
4724 4724
 				);
4725 4725
 
4726 4726
 			case 'multipart':
4727
-				switch($_structure->getSubType())
4727
+				switch ($_structure->getSubType())
4728 4728
 				{
4729 4729
 					case 'alternative':
4730 4730
 						$bodyParts = array($this->getMultipartAlternative($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
@@ -4758,7 +4758,7 @@  discard block
 block discarded – undo
4758 4758
 				$bodyPart = array();
4759 4759
 				if ($_structure->getDisposition() != 'attachment')
4760 4760
 				{
4761
-					switch($_structure->getSubType())
4761
+					switch ($_structure->getSubType())
4762 4762
 					{
4763 4763
 						case 'calendar':
4764 4764
 							// this is handeled in getTextPart
@@ -4774,11 +4774,11 @@  discard block
 block discarded – undo
4774 4774
 
4775 4775
 			case 'attachment':
4776 4776
 			case 'message':
4777
-				switch($_structure->getSubType())
4777
+				switch ($_structure->getSubType())
4778 4778
 				{
4779 4779
 					case 'rfc822':
4780 4780
 						$newStructure = $_structure->getParts();
4781
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4781
+						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]); }
4782 4782
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4783 4783
 				}
4784 4784
 				break;
@@ -4806,11 +4806,11 @@  discard block
 block discarded – undo
4806 4806
 	{
4807 4807
 		if (is_array($_bodyParts))
4808 4808
 		{
4809
-			foreach($_bodyParts as $singleBodyPart)
4809
+			foreach ($_bodyParts as $singleBodyPart)
4810 4810
 			{
4811 4811
 				if (!isset($singleBodyPart['body'])) {
4812 4812
 					$buff = self::normalizeBodyParts($singleBodyPart);
4813
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
4813
+					foreach ((array)$buff as $val) { $body2return[] = $val; }
4814 4814
 					continue;
4815 4815
 				}
4816 4816
 				$body2return[] = $singleBodyPart;
@@ -4831,14 +4831,14 @@  discard block
 block discarded – undo
4831 4831
 	 * @param boolean $useTidy  switch to use tidy
4832 4832
 	 * @return string a preformatted string with the mails converted to text
4833 4833
 	 */
4834
-	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false,  $useTidy = true)
4834
+	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false, $useTidy = true)
4835 4835
 	{
4836
-		$message='';
4837
-		for($i=0; $i<count($bodyParts); $i++)
4836
+		$message = '';
4837
+		for ($i = 0; $i < count($bodyParts); $i++)
4838 4838
 		{
4839 4839
 			if (!isset($bodyParts[$i]['body'])) {
4840 4840
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4841
-				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4841
+				$message .= empty($bodyParts[$i]['body']) ? '' : $bodyParts[$i]['body'];
4842 4842
 				continue;
4843 4843
 			}
4844 4844
 			if (isset($bodyParts[$i]['error'])) continue;
@@ -4863,32 +4863,32 @@  discard block
 block discarded – undo
4863 4863
 				'(R)',
4864 4864
 			);
4865 4865
 
4866
-			if(($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
4866
+			if (($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
4867 4867
 				strtoupper($bodyParts[$i]['charSet']) != 'UTF-8')
4868 4868
 			{
4869
-				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4869
+				$bodyParts[$i]['body'] = preg_replace($sar, $rar, $bodyParts[$i]['body']);
4870 4870
 			}
4871 4871
 
4872
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
4872
+			if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
4873 4873
 			// add line breaks to $bodyParts
4874 4874
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4875
-			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4875
+			$newBody = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4876 4876
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4877 4877
 			$mailClass->activeMimeType = 'text/plain';
4878 4878
 			if ($bodyParts[$i]['mimeType'] == 'text/html') {
4879 4879
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4880 4880
 				if (!$preserveHTML)
4881 4881
 				{
4882
-					$alreadyHtmlLawed=false;
4882
+					$alreadyHtmlLawed = false;
4883 4883
 					// as Translation::convert reduces \r\n to \n and purifier eats \n -> peplace it with a single space
4884
-					$newBody = str_replace("\n"," ",$newBody);
4884
+					$newBody = str_replace("\n", " ", $newBody);
4885 4885
 					// convert HTML to text, as we dont want HTML in infologs
4886 4886
 					if ($useTidy && extension_loaded('tidy'))
4887 4887
 					{
4888 4888
 						$tidy = new tidy();
4889
-						$cleaned = $tidy->repairString($newBody, self::$tidy_config,'utf8');
4889
+						$cleaned = $tidy->repairString($newBody, self::$tidy_config, 'utf8');
4890 4890
 						// Found errors. Strip it all so there's some output
4891
-						if($tidy->getStatus() == 2)
4891
+						if ($tidy->getStatus() == 2)
4892 4892
 						{
4893 4893
 							error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
4894 4894
 						}
@@ -4899,7 +4899,7 @@  discard block
 block discarded – undo
4899 4899
 						if (!$preserveHTML)
4900 4900
 						{
4901 4901
 							// filter only the 'body', as we only want that part, if we throw away the html
4902
-							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
4902
+							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
4903 4903
 							if ($matches[2])
4904 4904
 							{
4905 4905
 								$hasOther = true;
@@ -4910,7 +4910,7 @@  discard block
 block discarded – undo
4910 4910
 					else
4911 4911
 					{
4912 4912
 						// htmLawed filter only the 'body'
4913
-						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
4913
+						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
4914 4914
 						if ($matches[2])
4915 4915
 						{
4916 4916
 							$hasOther = true;
@@ -4919,17 +4919,17 @@  discard block
 block discarded – undo
4919 4919
 						$htmLawed = new Html\HtmLawed();
4920 4920
 						// the next line should not be needed, but produces better results on HTML 2 Text conversion,
4921 4921
 						// as we switched off HTMLaweds tidy functionality
4922
-						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
4923
-						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
4924
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
4925
-						$alreadyHtmlLawed=true;
4922
+						$newBody = str_replace(array('&amp;amp;', '<DIV><BR></DIV>', "<DIV>&nbsp;</DIV>", '<div>&nbsp;</div>'), array('&amp;', '<BR>', '<BR>', '<BR>'), $newBody);
4923
+						$newBody = $htmLawed->run($newBody, self::$htmLawed_config);
4924
+						if ($hasOther && $preserveHTML) $newBody = $matches[1].$newBody.$matches[3];
4925
+						$alreadyHtmlLawed = true;
4926 4926
 					}
4927 4927
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
4928
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
4928
+					if ($preserveHTML == false) $newBody = Mail\Html::convertHTMLToText($newBody, self::$displayCharset, true, true);
4929 4929
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
4930
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
4930
+					if ($preserveHTML == false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
4931 4931
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
4932
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
4932
+					if ($preserveHTML == false) $newBody = str_replace("<br />", "\r\n", $newBody);
4933 4933
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
4934 4934
 				}
4935 4935
 				$message .= $newBody;
@@ -4938,9 +4938,9 @@  discard block
 block discarded – undo
4938 4938
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after specialchars):'.$newBody);
4939 4939
 			//use Mail\Html::convertHTMLToText instead of strip_tags, (even message is plain text) as strip_tags eats away too much
4940 4940
 			//$newBody = strip_tags($newBody); //we need to fix broken tags (or just stuff like "<800 USD/p" )
4941
-			$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,false,false);
4941
+			$newBody = Mail\Html::convertHTMLToText($newBody, self::$displayCharset, false, false);
4942 4942
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after strip tags):'.$newBody);
4943
-			$newBody = htmlspecialchars_decode($newBody,ENT_QUOTES);
4943
+			$newBody = htmlspecialchars_decode($newBody, ENT_QUOTES);
4944 4944
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body (after hmlspc_decode):'.$newBody);
4945 4945
 			$message .= $newBody;
4946 4946
 			//continue;
@@ -4948,27 +4948,27 @@  discard block
 block discarded – undo
4948 4948
 		return $message;
4949 4949
 	}
4950 4950
 
4951
-	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false)
4951
+	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith = false)
4952 4952
 	{
4953 4953
 		$lines = explode("\n", $str);
4954 4954
 		$newStr = '';
4955
-		foreach($lines as $line)
4955
+		foreach ($lines as $line)
4956 4956
 		{
4957 4957
 			// replace tabs by 8 space chars, or any tab only counts one char
4958 4958
 			//$line = str_replace("\t","        ",$line);
4959 4959
 			//$newStr .= wordwrap($line, $cols, $cut);
4960
-			$allowedLength = $cols-strlen($cut);
4960
+			$allowedLength = $cols - strlen($cut);
4961 4961
 			//dont try to break lines with links, chance is we mess up the text is way too big
4962
-			if (strlen($line) > $allowedLength && stripos($line,'href=')===false &&
4963
-				($dontbreaklinesstartingwith==false ||
4962
+			if (strlen($line) > $allowedLength && stripos($line, 'href=') === false &&
4963
+				($dontbreaklinesstartingwith == false ||
4964 4964
 				 ($dontbreaklinesstartingwith &&
4965
-				  strlen($dontbreaklinesstartingwith)>=1 &&
4966
-				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
4965
+				  strlen($dontbreaklinesstartingwith) >= 1 &&
4966
+				  substr($line, 0, strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
4967 4967
 				 )
4968 4968
 				)
4969 4969
 			   )
4970 4970
 			{
4971
-				$s=explode(" ", $line);
4971
+				$s = explode(" ", $line);
4972 4972
 				$line = "";
4973 4973
 				$linecnt = 0;
4974 4974
 				foreach ($s as &$v) {
@@ -4976,22 +4976,22 @@  discard block
 block discarded – undo
4976 4976
 					// only break long words within the wordboundaries,
4977 4977
 					// but it may destroy links, so we check for href and dont do it if we find one
4978 4978
 					// we check for any html within the word, because we do not want to break html by accident
4979
-					if($cnt > $allowedLength && stripos($v,'href=')===false && stripos($v,'onclick=')===false && $cnt == strlen(html_entity_decode($v)))
4979
+					if ($cnt > $allowedLength && stripos($v, 'href=') === false && stripos($v, 'onclick=') === false && $cnt == strlen(html_entity_decode($v)))
4980 4980
 					{
4981
-						$v=wordwrap($v, $allowedLength, $cut, true);
4981
+						$v = wordwrap($v, $allowedLength, $cut, true);
4982 4982
 					}
4983 4983
 					// the rest should be broken at the start of the new word that exceeds the limit
4984
-					if ($linecnt+$cnt > $allowedLength) {
4985
-						$v=$cut.$v;
4984
+					if ($linecnt + $cnt > $allowedLength) {
4985
+						$v = $cut.$v;
4986 4986
 						#$linecnt = 0;
4987
-						$linecnt =strlen($v)-strlen($cut);
4987
+						$linecnt = strlen($v) - strlen($cut);
4988 4988
 					} else {
4989 4989
 						$linecnt += $cnt;
4990 4990
 					}
4991 4991
 					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
4992 4992
 				}
4993 4993
 			}
4994
-			$newStr .= $line . "\n";
4994
+			$newStr .= $line."\n";
4995 4995
 		}
4996 4996
 		return $newStr;
4997 4997
 	}
@@ -5006,12 +5006,12 @@  discard block
 block discarded – undo
5006 5006
 	 * @param boolean $_useHeaderInsteadOfEnvelope - force getMessageHeader method to be used for fetching Envelope Information
5007 5007
 	 * @return array the message header
5008 5008
 	 */
5009
-	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5009
+	function getMessageEnvelope($_uid, $_partID = '', $decode = false, $_folder = '', $_useHeaderInsteadOfEnvelope = false)
5010 5010
 	{
5011 5011
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5012
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5012
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5013 5013
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5014
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
5014
+		if ((empty($_partID) || $_partID == 'null') && $_useHeaderInsteadOfEnvelope === false) {
5015 5015
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5016 5016
 			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5017 5017
 			$uidsToFetch->add($_uid);
@@ -5024,7 +5024,7 @@  discard block
 block discarded – undo
5024 5024
 				'ids' => $uidsToFetch,
5025 5025
 			));
5026 5026
 			if (is_object($headersNew)) {
5027
-				foreach($headersNew as &$_headerObject) {
5027
+				foreach ($headersNew as &$_headerObject) {
5028 5028
 					$env = $_headerObject->getEnvelope();
5029 5029
 					//_debug_array($envFields->singleFields());
5030 5030
 					$singleFields = $envFields->singleFields();
@@ -5039,34 +5039,34 @@  discard block
 block discarded – undo
5039 5039
 							case 'bcc':
5040 5040
 							case 'sender':
5041 5041
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5042
-								$envelope[$v]=$env->$v->addresses;
5042
+								$envelope[$v] = $env->$v->addresses;
5043 5043
 								$address = array();
5044 5044
 								if (!is_array($envelope[$v])) break;
5045 5045
 								foreach ($envelope[$v] as $k => $ad)
5046 5046
 								{
5047
-									if (stripos($ad,'@')===false)
5047
+									if (stripos($ad, '@') === false)
5048 5048
 									{
5049
-										$remember=$k;
5049
+										$remember = $k;
5050 5050
 									}
5051 5051
 									else
5052 5052
 									{
5053
-										$address[] = (!is_null($remember)?$envelope[$v][$remember].' ':'').$ad;
5054
-										$remember=null;
5053
+										$address[] = (!is_null($remember) ? $envelope[$v][$remember].' ' : '').$ad;
5054
+										$remember = null;
5055 5055
 									}
5056 5056
 								}
5057 5057
 								$envelope[$v] = $address;
5058 5058
 								break;
5059 5059
 							case 'date':
5060
-								$envelope[$v]=DateTime::to($env->$v);
5060
+								$envelope[$v] = DateTime::to($env->$v);
5061 5061
 								break;
5062 5062
 							default:
5063
-								$envelope[$v]=$env->$v;
5063
+								$envelope[$v] = $env->$v;
5064 5064
 						}
5065 5065
 					}
5066
-					$envelope['size']=$_headerObject->getSize();
5066
+					$envelope['size'] = $_headerObject->getSize();
5067 5067
 				}
5068 5068
 			}
5069
-			$envelope = array_change_key_case($envelope,CASE_UPPER);
5069
+			$envelope = array_change_key_case($envelope, CASE_UPPER);
5070 5070
 			//if ($decode) _debug_array($envelope);
5071 5071
 			//error_log(__METHOD__.' ('.__LINE__.') '.array2string($envelope));
5072 5072
 			if ($decode)
@@ -5074,19 +5074,19 @@  discard block
 block discarded – undo
5074 5074
 				foreach ($envelope as $key => $rvV)
5075 5075
 				{
5076 5076
 					//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
5077
-					$envelope[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5077
+					$envelope[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5078 5078
 				}
5079 5079
 			}
5080 5080
 			return $envelope;
5081 5081
 		} else {
5082 5082
 
5083
-			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5083
+			$headers = $this->getMessageHeader($_uid, $_partID, true, true, $_folder);
5084 5084
 
5085 5085
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($headers));
5086 5086
 			//_debug_array($headers);
5087 5087
 			$newData = array(
5088 5088
 				'DATE'		=> $headers['DATE'],
5089
-				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5089
+				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']) : $headers['SUBJECT']),
5090 5090
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5091 5091
 			);
5092 5092
 			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
@@ -5097,11 +5097,11 @@  discard block
 block discarded – undo
5097 5097
 			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
5098 5098
 			//_debug_array($newData);
5099 5099
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5100
-			foreach($recepientList as $recepientType) {
5101
-				if(isset($headers[$recepientType])) {
5102
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
5100
+			foreach ($recepientList as $recepientType) {
5101
+				if (isset($headers[$recepientType])) {
5102
+					if ($decode) $headers[$recepientType] = self::decode_header($headers[$recepientType], true);
5103 5103
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5104
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5104
+					foreach (self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5105 5105
 						$addressData = array(
5106 5106
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5107 5107
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5109,15 +5109,15 @@  discard block
 block discarded – undo
5109 5109
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5110 5110
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5111 5111
 						);
5112
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
5112
+						if ($addressData['PERSONAL_NAME'] != 'NIL') {
5113 5113
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5114 5114
 						} else {
5115 5115
 							$addressData['RFC822_EMAIL'] = 'NIL';
5116 5116
 						}
5117
-						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5117
+						$newData[$recepientType][] = ($addressData['RFC822_EMAIL'] != 'NIL' ? $addressData['RFC822_EMAIL'] : $addressData['EMAIL']); //$addressData;
5118 5118
 					}
5119 5119
 				} else {
5120
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
5120
+					if ($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
5121 5121
 						$newData[$recepientType] = $newData['FROM'];
5122 5122
 					} else {
5123 5123
 						$newData[$recepientType] = array();
@@ -5139,10 +5139,10 @@  discard block
 block discarded – undo
5139 5139
 	 * @param string $_folder folder to work on
5140 5140
 	 * @return array|Horde_Mime_Headers message header as array or object
5141 5141
 	 */
5142
-	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5142
+	function getMessageHeader($_uid, $_partID = '', $decode = false, $preserveUnSeen = false, $_folder = '')
5143 5143
 	{
5144 5144
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5145
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5145
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5146 5146
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5147 5147
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5148 5148
 		$uidsToFetch->add($_uid);
@@ -5150,7 +5150,7 @@  discard block
 block discarded – undo
5150 5150
 		$fquery = new Horde_Imap_Client_Fetch_Query();
5151 5151
 		if ($_partID != '')
5152 5152
 		{
5153
-			$fquery->headerText(array('id'=>$_partID,'peek'=>$preserveUnSeen));
5153
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>$preserveUnSeen));
5154 5154
 			$fquery->structure();
5155 5155
 		}
5156 5156
 		else
@@ -5163,18 +5163,18 @@  discard block
 block discarded – undo
5163 5163
 			'ids' => $uidsToFetch,
5164 5164
 		));
5165 5165
 		if (is_object($headersNew)) {
5166
-			foreach($headersNew as $_fetchObject)
5166
+			foreach ($headersNew as $_fetchObject)
5167 5167
 			{
5168
-				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5168
+				$headers = $_fetchObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5169 5169
 				if ($_partID != '')
5170 5170
 				{
5171 5171
 					$mailStructureObject = $_fetchObject->getStructure();
5172 5172
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5173 5173
 					{
5174
-						if ($mime_id==$_partID)
5174
+						if ($mime_id == $_partID)
5175 5175
 						{
5176 5176
 							//error_log(__METHOD__.' ('.__LINE__.') '."$mime_id == $_partID".array2string($_headerObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray()));
5177
-							$headers = $_fetchObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5177
+							$headers = $_fetchObject->getHeaderText($mime_id, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5178 5178
 							break;
5179 5179
 						}
5180 5180
 					}
@@ -5187,15 +5187,15 @@  discard block
 block discarded – undo
5187 5187
 				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
5188 5188
 				return $headers;
5189 5189
 			}
5190
-			$retValue = is_object($headers) ? $headers->toArray():array();
5190
+			$retValue = is_object($headers) ? $headers->toArray() : array();
5191 5191
 			if ($size) $retValue['size'] = $size;
5192 5192
 		}
5193
-		$retValue = array_change_key_case($retValue,CASE_UPPER);
5193
+		$retValue = array_change_key_case($retValue, CASE_UPPER);
5194 5194
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
5195 5195
 		// if SUBJECT is an array, use thelast one, as we assume something with the unfolding for the subject did not work
5196 5196
 		if (is_array($retValue['SUBJECT']))
5197 5197
 		{
5198
-			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT'])-1];
5198
+			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT']) - 1];
5199 5199
 		}
5200 5200
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($decode ? self::decode_header($retValue,true):$retValue));
5201 5201
 		if ($decode)
@@ -5203,7 +5203,7 @@  discard block
 block discarded – undo
5203 5203
 			foreach ($retValue as $key => $rvV)
5204 5204
 			{
5205 5205
 				//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
5206
-				$retValue[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5206
+				$retValue[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5207 5207
 			}
5208 5208
 		}
5209 5209
 		return $retValue;
@@ -5220,14 +5220,14 @@  discard block
 block discarded – undo
5220 5220
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5221 5221
 	{
5222 5222
 		static $rawHeaders;
5223
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5223
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5224 5224
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5225 5225
 
5226
-		if (is_null($rawHeaders)||!is_array($rawHeaders)) $rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
5227
-		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5226
+		if (is_null($rawHeaders) || !is_array($rawHeaders)) $rawHeaders = Cache::getCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
5227
+		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5228 5228
 		{
5229 5229
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5230
-			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5230
+			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5231 5231
 		}
5232 5232
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5233 5233
 		$uid = $_uid;
@@ -5237,7 +5237,7 @@  discard block
 block discarded – undo
5237 5237
 		$fquery = new Horde_Imap_Client_Fetch_Query();
5238 5238
 		if ($_partID != '')
5239 5239
 		{
5240
-			$fquery->headerText(array('id'=>$_partID,'peek'=>true));
5240
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>true));
5241 5241
 			$fquery->structure();
5242 5242
 		}
5243 5243
 		else
@@ -5248,14 +5248,14 @@  discard block
 block discarded – undo
5248 5248
 			'ids' => $uidsToFetch,
5249 5249
 		));
5250 5250
 		if (is_object($headersNew)) {
5251
-			foreach($headersNew as &$_headerObject) {
5251
+			foreach ($headersNew as &$_headerObject) {
5252 5252
 				$retValue = $_headerObject->getHeaderText();
5253 5253
 				if ($_partID != '')
5254 5254
 				{
5255 5255
 					$mailStructureObject = $_headerObject->getStructure();
5256 5256
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5257 5257
 					{
5258
-						if ($mime_id==$_partID)
5258
+						if ($mime_id == $_partID)
5259 5259
 						{
5260 5260
 							$retValue = $_headerObject->getHeaderText($mime_id);
5261 5261
 						}
@@ -5263,8 +5263,8 @@  discard block
 block discarded – undo
5263 5263
 				}
5264 5264
 			}
5265 5265
 		}
5266
-		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]=$retValue;
5267
-		Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),$rawHeaders,60*60*1);
5266
+		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $retValue;
5267
+		Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']), $rawHeaders, 60 * 60 * 1);
5268 5268
 		return $retValue;
5269 5269
 	}
5270 5270
 
@@ -5277,25 +5277,25 @@  discard block
 block discarded – undo
5277 5277
 	{
5278 5278
 		$style = '';
5279 5279
 		if (empty($_bodyParts)) return "";
5280
-		foreach((array)$_bodyParts as $singleBodyPart) {
5280
+		foreach ((array)$_bodyParts as $singleBodyPart) {
5281 5281
 			if (!isset($singleBodyPart['body'])) {
5282 5282
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5283 5283
 				$style .= $singleBodyPart['body'];
5284 5284
 				continue;
5285 5285
 			}
5286 5286
 
5287
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
5287
+			if ($singleBodyPart['charSet'] === false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
5288 5288
 			$singleBodyPart['body'] = Translation::convert(
5289 5289
 				$singleBodyPart['body'],
5290 5290
 				strtolower($singleBodyPart['charSet'])
5291 5291
 			);
5292 5292
 			$ct = 0;
5293
-			$newStyle=array();
5294
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5295
-			if ($ct>0)
5293
+			$newStyle = array();
5294
+			if (stripos($singleBodyPart['body'], '<style') !== false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5295
+			if ($ct > 0)
5296 5296
 			{
5297 5297
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
5298
-				$style2buffer = implode('',$newStyle[0]);
5298
+				$style2buffer = implode('', $newStyle[0]);
5299 5299
 			}
5300 5300
 			if ($style2buffer && strtoupper(self::$displayCharset) == 'UTF-8')
5301 5301
 			{
@@ -5303,7 +5303,7 @@  discard block
 block discarded – undo
5303 5303
 				$test = json_encode($style2buffer);
5304 5304
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$test.'# ->'.strlen($style2buffer).' Error:'.json_last_error());
5305 5305
 				//if (json_last_error() != JSON_ERROR_NONE && strlen($style2buffer)>0)
5306
-				if ($test=="null" && strlen($style2buffer)>0)
5306
+				if ($test == "null" && strlen($style2buffer) > 0)
5307 5307
 				{
5308 5308
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
5309 5309
 					error_log(__METHOD__.' ('.__LINE__.') '.' Found Invalid sequence for utf-8 in CSS:'.$style2buffer.' Charset Reported:'.$singleBodyPart['charSet'].' Carset Detected:'.Translation::detect_encoding($style2buffer));
@@ -5314,19 +5314,19 @@  discard block
 block discarded – undo
5314 5314
 		}
5315 5315
 		// clean out comments and stuff
5316 5316
 		$search = array(
5317
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
5317
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
5318 5318
 //			'@<!--[\s\S]*?[ \t\n\r]*-->@',   // Strip multi-line comments including CDATA
5319 5319
 //			'@<!--[\s\S]*?[ \t\n\r]*--@',    // Strip broken multi-line comments including CDATA
5320 5320
 		);
5321
-		$style = preg_replace($search,"",$style);
5321
+		$style = preg_replace($search, "", $style);
5322 5322
 
5323 5323
 		// CSS Security
5324 5324
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5325
-		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5326
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
5325
+		$css = preg_replace('/(javascript|expression|-moz-binding)/i', '', $style);
5326
+		if (stripos($css, 'script') !== false) Mail\Html::replaceTagsCompletley($css, 'script'); // Strip out script that may be included
5327 5327
 		// we need this, as styledefinitions are enclosed with curly brackets; and template stuff tries to replace everything between curly brackets that is having no horizontal whitespace
5328 5328
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5329
-		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
5329
+		$css = str_replace(array(':', '<!--', '-->'), array(': ', '', ''), $css);
5330 5330
 		//error_log(__METHOD__.' ('.__LINE__.') '.$css);
5331 5331
 		// TODO: we may have to strip urls and maybe comments and ifs
5332 5332
 		return $css;
@@ -5340,16 +5340,16 @@  discard block
 block discarded – undo
5340 5340
 	 * @param string $_folder folder to work on
5341 5341
 	 * @return string the message body
5342 5342
 	 */
5343
-	function getMessageRawBody($_uid, $_partID = '', $_folder='')
5343
+	function getMessageRawBody($_uid, $_partID = '', $_folder = '')
5344 5344
 	{
5345 5345
 		//TODO: caching einbauen static!
5346 5346
 		static $rawBody;
5347 5347
 		if (is_null($rawBody)) $rawBody = array();
5348
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5349
-		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5348
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5349
+		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5350 5350
 		{
5351 5351
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
5352
-			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5352
+			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5353 5353
 		}
5354 5354
 
5355 5355
 		$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -5362,13 +5362,13 @@  discard block
 block discarded – undo
5362 5362
 		if ($_partID != '')
5363 5363
 		{
5364 5364
 			$fquery->structure();
5365
-			$fquery->bodyPart($_partID,array('peek'=>true));
5365
+			$fquery->bodyPart($_partID, array('peek'=>true));
5366 5366
 		}
5367 5367
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5368 5368
 			'ids' => $uidsToFetch,
5369 5369
 		));
5370 5370
 		if (is_object($headersNew)) {
5371
-			foreach($headersNew as &$_headerObject) {
5371
+			foreach ($headersNew as &$_headerObject) {
5372 5372
 				$body = $_headerObject->getFullMsg();
5373 5373
 				if ($_partID != '')
5374 5374
 				{
@@ -5376,7 +5376,7 @@  discard block
 block discarded – undo
5376 5376
 					//_debug_array($mailStructureObject->contentTypeMap());
5377 5377
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5378 5378
 					{
5379
-						if ($mime_id==$_partID)
5379
+						if ($mime_id == $_partID)
5380 5380
 						{
5381 5381
 							$body = $_headerObject->getBodyPart($mime_id);
5382 5382
 						}
@@ -5385,7 +5385,7 @@  discard block
 block discarded – undo
5385 5385
 			}
5386 5386
 		}
5387 5387
 		//error_log(__METHOD__.' ('.__LINE__.') '."[$this->icServer->ImapServerId][$_folder][$_uid][".(empty($_partID)?'NIL':$_partID)."]");
5388
-		$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)] = $body;
5388
+		$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $body;
5389 5389
 		return $body;
5390 5390
 	}
5391 5391
 
@@ -5399,13 +5399,13 @@  discard block
 block discarded – undo
5399 5399
 	 * @param Horde_Imap_Client_Fetch_Query $fquery=null default query just structure
5400 5400
 	 * @return Horde_Mime_Part
5401 5401
 	 */
5402
-	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5402
+	function getStructure($_uid, $_partID = null, $_folder = null, $_preserveSeen = false)
5403 5403
 	{
5404
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5404
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5405 5405
 
5406 5406
 		if (empty($_folder))
5407 5407
 		{
5408
-			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5408
+			$_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5409 5409
 		}
5410 5410
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5411 5411
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5423,7 +5423,7 @@  discard block
 block discarded – undo
5423 5423
 				'ids' => $uidsToFetch,
5424 5424
 			))->first();
5425 5425
 
5426
-			return is_object($mail)?$mail->getStructure():null;
5426
+			return is_object($mail) ? $mail->getStructure() : null;
5427 5427
 		}
5428 5428
 		catch (\Exception $e)
5429 5429
 		{
@@ -5446,14 +5446,14 @@  discard block
 block discarded – undo
5446 5446
 	 * @param string $_folder folder to work on
5447 5447
 	 * @return array  an array of information about the attachment: array of array(name, size, mimeType, partID, encoding)
5448 5448
 	 */
5449
-	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5449
+	function getMessageAttachments($_uid, $_partID = null, Horde_Mime_Part $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = false, $resolveTNEF = true, $_folder = '')
5450 5450
 	{
5451
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5452
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5451
+		if (self::$debug) error_log(__METHOD__.":$_uid, $_partID");
5452
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5453 5453
 		$attachments = array();
5454 5454
 		if (!isset($_structure))
5455 5455
 		{
5456
-			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5456
+			$_structure = $this->getStructure($_uid, $_partID, $_folder, true);
5457 5457
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5458 5458
 		}
5459 5459
 		if (!$_structure || !$_structure->contentTypeMap()) return array();
@@ -5461,7 +5461,7 @@  discard block
 block discarded – undo
5461 5461
 		$skipParts = array();
5462 5462
 		$tnefParts = array();
5463 5463
 		$skip = 0;
5464
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
5464
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
5465 5465
 		{
5466 5466
 			// skip multipart/encrypted incl. its two sub-parts, as we show 2. sub-part as body to be decrypted client-side
5467 5467
 			if ($mime_type == 'multipart/encrypted')
@@ -5469,7 +5469,7 @@  discard block
 block discarded – undo
5469 5469
 				$skip = 2;
5470 5470
 				continue;
5471 5471
 			}
5472
-			elseif($skip)
5472
+			elseif ($skip)
5473 5473
 			{
5474 5474
 				$skip--;
5475 5475
 				continue;
@@ -5483,10 +5483,10 @@  discard block
 block discarded – undo
5483 5483
 			$partPrimaryType = $part->getPrimaryType();
5484 5484
 			// we only want to retrieve the attachments of the current mail, not those of possible
5485 5485
 			// attached mails
5486
-			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5486
+			if ($mime_type == 'message/rfc822' && $_partID != $mime_id)
5487 5487
 			{
5488 5488
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5489
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
5489
+				foreach ($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
5490 5490
 			}
5491 5491
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5492 5492
 			{
@@ -5494,27 +5494,27 @@  discard block
 block discarded – undo
5494 5494
 				// attachment with no link to show the attachment inline.
5495 5495
 				// Considering this: we "list" everything that matches the above criteria
5496 5496
 				// as attachment in order to not loose/miss information on our data
5497
-				$partDisposition='attachment';
5497
+				$partDisposition = 'attachment';
5498 5498
 			}
5499 5499
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5500
-			if (array_key_exists($mime_id,$skipParts)) continue;
5500
+			if (array_key_exists($mime_id, $skipParts)) continue;
5501 5501
 
5502 5502
 			if ($partDisposition == 'attachment' ||
5503
-				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
5503
+				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId() == '') ||
5504 5504
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType != 'image' && $partPrimaryType != 'text' && $partPrimaryType != 'multipart') ||
5505
-				($mime_type=='image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5505
+				($mime_type == 'image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5506 5506
 				($fetchEmbeddedImages && ($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image') ||
5507 5507
 				($fetchTextCalendar && $partPrimaryType == 'text' && $part->getSubType() == 'calendar'))
5508 5508
 			{
5509 5509
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5510 5510
 				// we attempt to fetch "ourselves"
5511
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
5511
+				if ($_partID == $part->getMimeId() && $part->getPrimaryType() == 'message') continue;
5512 5512
 				$attachment = $part->getAllDispositionParameters();
5513 5513
 				$attachment['disposition'] = $part->getDisposition();
5514 5514
 				$attachment['mimeType'] = $mime_type;
5515 5515
 				$attachment['uid'] = $_uid;
5516 5516
 				$attachment['partID'] = $mime_id;
5517
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5517
+				if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5518 5518
 				if ($fetchTextCalendar)
5519 5519
 				{
5520 5520
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
@@ -5524,11 +5524,11 @@  discard block
 block discarded – undo
5524 5524
 				}
5525 5525
 				$attachment['size'] = $part->getBytes();
5526 5526
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5527
-				if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
5527
+				if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid']) && !empty($attachment['cid']) ? $attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
5528 5528
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5529 5529
 				//typical winmail.dat attachment is
5530 5530
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
5531
-				if ($resolveTNEF && ($attachment['mimeType']=='application/ms-tnef' || !strcasecmp($attachment['name'],'winmail.dat')))
5531
+				if ($resolveTNEF && ($attachment['mimeType'] == 'application/ms-tnef' || !strcasecmp($attachment['name'], 'winmail.dat')))
5532 5532
 				{
5533 5533
 					$tnefParts[] = $attachment;
5534 5534
 				}
@@ -5543,31 +5543,31 @@  discard block
 block discarded – undo
5543 5543
 			//error_log(__METHOD__.__LINE__.array2string($tnefParts));
5544 5544
 			foreach ($tnefParts as $k => $tnp)
5545 5545
 			{
5546
-				$tnefResolved=false;
5547
-				$tnef_data = $this->getAttachment($tnp['uid'],$tnp['partID'],$k,false);
5546
+				$tnefResolved = false;
5547
+				$tnef_data = $this->getAttachment($tnp['uid'], $tnp['partID'], $k, false);
5548 5548
 				$myTnef = $this->tnef_decoder($tnef_data['attachment']);
5549 5549
 				//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5550 5550
 				// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5551 5551
 				// we need to build Something that meets the needs
5552 5552
 				if ($myTnef)
5553 5553
 				{
5554
-					foreach($myTnef->getParts() as $mime_id => $part)
5554
+					foreach ($myTnef->getParts() as $mime_id => $part)
5555 5555
 					{
5556
-						$tnefResolved=true;
5556
+						$tnefResolved = true;
5557 5557
 						$attachment = $part->getAllDispositionParameters();
5558 5558
 						$attachment['disposition'] = $part->getDisposition();
5559 5559
 						$attachment['mimeType'] = $part->getType();
5560 5560
 						$attachment['uid'] = $tnp['uid'];
5561 5561
 						$attachment['partID'] = $tnp['partID'];
5562 5562
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5563
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5563
+						if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5564 5564
 						$attachment['size'] = $part->getBytes();
5565 5565
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5566
-						if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5566
+						if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid']) && !empty($attachment['cid']) ? $attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5567 5567
 						$attachments[] = $attachment;
5568 5568
 					}
5569 5569
 				}
5570
-				if ($tnefResolved===false) $attachments[]=$tnp;
5570
+				if ($tnefResolved === false) $attachments[] = $tnp;
5571 5571
 			}
5572 5572
 		}
5573 5573
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5582,9 +5582,9 @@  discard block
 block discarded – undo
5582 5582
 	 * @return boolean|Horde_Mime_part Multipart/Mixed part decoded attachments |
5583 5583
 	 *	return false if there's no attachments or failure
5584 5584
 	 */
5585
-	public function tnef_decoder( $data )
5585
+	public function tnef_decoder($data)
5586 5586
 	{
5587
-		foreach(array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5587
+		foreach (array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5588 5588
 		{
5589 5589
 			if (!class_exists($class))
5590 5590
 			{
@@ -5616,7 +5616,7 @@  discard block
 block discarded – undo
5616 5616
 				$tmp_part->setContents($data['stream']);
5617 5617
 				$tmp_part->setDescription($data['name']);
5618 5618
 
5619
-				$type = $data['type'] . '/' . $data['subtype'];
5619
+				$type = $data['type'].'/'.$data['subtype'];
5620 5620
 				if (in_array($type, array('application/octet-stream', 'application/base64')))
5621 5621
 				{
5622 5622
 					$type = Horde_Mime_Magic::filenameToMIME($data['name']);
@@ -5659,24 +5659,24 @@  discard block
 block discarded – undo
5659 5659
 	 *
5660 5660
 	 * @return array returns an array of all resolved embeded attachments from winmail.dat
5661 5661
 	 */
5662
-	function getTnefAttachments ($_uid, $_partID, $_stream=false)
5662
+	function getTnefAttachments($_uid, $_partID, $_stream = false)
5663 5663
 	{
5664
-		$tnef_data = $this->getAttachment($_uid, $_partID,0,false);
5664
+		$tnef_data = $this->getAttachment($_uid, $_partID, 0, false);
5665 5665
 		$tnef_parts = $this->tnef_decoder($tnef_data['attachment']);
5666 5666
 		$attachments = array();
5667 5667
 		if ($tnef_parts)
5668 5668
 		{
5669
-			foreach($tnef_parts->getParts() as $mime_id => $part)
5669
+			foreach ($tnef_parts->getParts() as $mime_id => $part)
5670 5670
 			{
5671 5671
 
5672 5672
 				$attachment = $part->getAllDispositionParameters();
5673 5673
 				$attachment['mimeType'] = $part->getType();
5674
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5674
+				if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5675 5675
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5676 5676
 				if (empty($attachment['filename']))
5677 5677
 				{
5678
-					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
5679
-						$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5678
+					$attachment['filename'] = (isset($attachment['cid']) && !empty($attachment['cid']) ?
5679
+						$attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5680 5680
 				}
5681 5681
 
5682 5682
 				$attachment['attachment'] = $part->getContents(array('stream'=>$_stream));
@@ -5700,10 +5700,10 @@  discard block
 block discarded – undo
5700 5700
 	 *
5701 5701
 	 * @return array
5702 5702
 	 */
5703
-	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5703
+	function getAttachment($_uid, $_partID, $_winmail_nr = 0, $_returnPart = true, $_stream = false, $_folder = null)
5704 5704
 	{
5705 5705
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5706
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5706
+		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5707 5707
 
5708 5708
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5709 5709
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5716,36 +5716,36 @@  discard block
 block discarded – undo
5716 5716
 			'ids' => $uidsToFetch,
5717 5717
 		));
5718 5718
 		if (is_object($headersNew)) {
5719
-			foreach($headersNew as $id=>$_headerObject) {
5719
+			foreach ($headersNew as $id=>$_headerObject) {
5720 5720
 				$body = $_headerObject->getFullMsg();
5721 5721
 				if ($_partID != '')
5722 5722
 				{
5723 5723
 					$mailStructureObject = $_headerObject->getStructure();
5724 5724
 					$mailStructureObject->contentTypeMap();
5725 5725
 					$part = $mailStructureObject->getPart($_partID);
5726
-					$partDisposition = ($part?$part->getDisposition():'failed');
5727
-					if ($partDisposition=='failed')
5726
+					$partDisposition = ($part ? $part->getDisposition() : 'failed');
5727
+					if ($partDisposition == 'failed')
5728 5728
 					{
5729 5729
 						error_log(__METHOD__.'('.__LINE__.'):'.array2string($_uid).','.$_partID.' ID:'.$id.' HObject:'.array2string($_headerObject).' StructureObject:'.array2string($mailStructureObject->contentTypeMap()).'->'.function_backtrace());
5730 5730
 					}
5731 5731
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5732 5732
 					// itself is only triggered to fetch attachments
5733
-					if (empty($partDisposition)) $partDisposition='attachment';
5734
-					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5733
+					if (empty($partDisposition)) $partDisposition = 'attachment';
5734
+					if ($part && ($partDisposition == 'attachment' || $partDisposition == 'inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5735 5735
 					{
5736 5736
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
5737 5737
 						$structure_mime = $part->getType();
5738 5738
 						$filename = $part->getName();
5739 5739
 						$charset = $part->getContentTypeParameter('charset');
5740 5740
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5741
-						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5741
+						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen = true, $structure_mime);
5742 5742
 						if ($_returnPart) return $part;
5743 5743
 					}
5744 5744
 				}
5745 5745
 			}
5746 5746
 		}
5747 5747
 		$ext = MimeMagic::mime2ext($structure_mime);
5748
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
5748
+		if ($ext && stripos($filename, '.') === false && stripos($filename, $ext) === false) $filename = trim($filename).'.'.$ext;
5749 5749
 		if (!$part)
5750 5750
 		{
5751 5751
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5763,20 +5763,20 @@  discard block
 block discarded – undo
5763 5763
 		// try guessing the mimetype, if we get the application/octet-stream
5764 5764
 		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
5765 5765
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5766
-		if ( $filename == 'winmail.dat' && $_winmail_nr)
5766
+		if ($filename == 'winmail.dat' && $_winmail_nr)
5767 5767
 		{
5768 5768
 			//by now _uid is of type array
5769
-			$tnefResolved=false;
5770
-			$wantedPart=$_uid[0].'@'.$_partID;
5769
+			$tnefResolved = false;
5770
+			$wantedPart = $_uid[0].'@'.$_partID;
5771 5771
 			$myTnef = $this->tnef_decoder($attachmentData['attachment']);
5772 5772
 			//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5773 5773
 			// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5774 5774
 			// we need to build Something that meets the needs
5775 5775
 			if ($myTnef)
5776 5776
 			{
5777
-				foreach($myTnef->getParts() as $mime_id => $part)
5777
+				foreach ($myTnef->getParts() as $mime_id => $part)
5778 5778
 				{
5779
-					$tnefResolved=true;
5779
+					$tnefResolved = true;
5780 5780
 					$attachment = $part->getAllDispositionParameters();
5781 5781
 					$attachment['mimeType'] = $part->getType();
5782 5782
 					//error_log(__METHOD__.__LINE__.'#'.$mime_id.'#'.$filename.'#'.array2string($attachment));
@@ -5784,9 +5784,9 @@  discard block
 block discarded – undo
5784 5784
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5785 5785
 					{
5786 5786
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5787
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5787
+						if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5788 5788
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5789
-						if (empty($attachment['filename'])) $attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5789
+						if (empty($attachment['filename'])) $attachment['filename'] = (isset($attachment['cid']) && !empty($attachment['cid']) ? $attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5790 5790
 						$wmattach = $attachment;
5791 5791
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5792 5792
 
@@ -5796,7 +5796,7 @@  discard block
 block discarded – undo
5796 5796
 			if ($tnefResolved)
5797 5797
 			{
5798 5798
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5799
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5799
+				if ($ext && stripos($wmattach['filename'], '.') === false && stripos($wmattach['filename'], $ext) === false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5800 5800
 				$attachmentData = array(
5801 5801
 					'type'       => $wmattach['mimeType'],
5802 5802
 					'filename'   => $wmattach['filename'],
@@ -5820,21 +5820,21 @@  discard block
 block discarded – undo
5820 5820
 	 *	true:
5821 5821
 	 * @return Horde_Mime_Part
5822 5822
 	 */
5823
-	function getAttachmentByCID($_uid, $_cid, $_part, $_stream=null)
5823
+	function getAttachmentByCID($_uid, $_cid, $_part, $_stream = null)
5824 5824
 	{
5825 5825
 		// some static variables to avoid fetching the same mail multiple times
5826
-		static $uid=null, $part=null, $structure=null;
5826
+		static $uid = null, $part = null, $structure = null;
5827 5827
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5828 5828
 
5829
-		if(empty($_cid)) return false;
5829
+		if (empty($_cid)) return false;
5830 5830
 
5831 5831
 		if ($_uid != $uid || $_part != $part)
5832 5832
 		{
5833
-			$structure = $this->getStructure($uid=$_uid, $part=$_part);
5833
+			$structure = $this->getStructure($uid = $_uid, $part = $_part);
5834 5834
 		}
5835 5835
 		/** @var Horde_Mime_Part */
5836 5836
 		$attachment = null;
5837
-		foreach($structure->contentTypeMap() as $mime_id => $mime_type)
5837
+		foreach ($structure->contentTypeMap() as $mime_id => $mime_type)
5838 5838
 		{
5839 5839
 			$part = $structure->getPart($mime_id);
5840 5840
 
@@ -5886,16 +5886,16 @@  discard block
 block discarded – undo
5886 5886
 	 * @param string  $_mimetype to decide wether to try to fetch part as binary or not
5887 5887
 	 * @return Horde_Mime_Part
5888 5888
 	 */
5889
-	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
5889
+	public function fetchPartContents($_uid, Horde_Mime_Part $part = null, $_stream = false, $_preserveSeen = false, $_mimetype = null)
5890 5890
 	{
5891
-		if (is_null($part)) return null;//new Horde_Mime_Part;
5891
+		if (is_null($part)) return null; //new Horde_Mime_Part;
5892 5892
 		$encoding = null;
5893 5893
 		$fetchAsBinary = true;
5894
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
5894
+		if ($_mimetype && strtolower($_mimetype) == 'message/rfc822') $fetchAsBinary = false;
5895 5895
 		// we need to set content on structure to decode transfer encoding
5896 5896
 		$part->setContents(
5897 5897
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
5898
-			array('encoding' => (!$fetchAsBinary&&!$encoding?'8bit':$encoding)));
5898
+			array('encoding' => (!$fetchAsBinary && !$encoding ? '8bit' : $encoding)));
5899 5899
 
5900 5900
 		return $part;
5901 5901
 	}
@@ -5913,17 +5913,17 @@  discard block
 block discarded – undo
5913 5913
 	 * @return the id of the message appended or exception
5914 5914
 	 * @throws Exception\WrongUserinput
5915 5915
 	 */
5916
-	function appendMessage($_folderName, $_header, $_body, $_flags='\\Recent')
5916
+	function appendMessage($_folderName, $_header, $_body, $_flags = '\\Recent')
5917 5917
 	{
5918 5918
 		if (!is_resource($_header))
5919 5919
 		{
5920
-			if (stripos($_header,'message-id:')===false)
5920
+			if (stripos($_header, 'message-id:') === false)
5921 5921
 			{
5922 5922
 				$_header = 'Message-ID: <'.self::getRandomString().'@localhost>'."\n".$_header;
5923 5923
 			}
5924 5924
 			//error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_header, $_body, $_flags");
5925
-			$_header = ltrim(str_replace("\n","\r\n",$_header));
5926
-			$_header .= str_replace("\n","\r\n",$_body);
5925
+			$_header = ltrim(str_replace("\n", "\r\n", $_header));
5926
+			$_header .= str_replace("\n", "\r\n", $_body);
5927 5927
 		}
5928 5928
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
5929 5929
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
@@ -5941,7 +5941,7 @@  discard block
 block discarded – undo
5941 5941
 			// searched for the message-id then returning the uid found
5942 5942
 			//$dataNflags[] = array('data'=>array(array('t'=>'text','v'=>"$header"."$body")), 'flags'=>array($_flags));
5943 5943
 			$dataNflags[] = array('data' => $_header, 'flags'=>array($_flags));
5944
-			$messageid = $this->icServer->append($_folderName,$dataNflags);
5944
+			$messageid = $this->icServer->append($_folderName, $dataNflags);
5945 5945
 		}
5946 5946
 		catch (\Exception $e)
5947 5947
 		{
@@ -5953,7 +5953,7 @@  discard block
 block discarded – undo
5953 5953
 		//$messageid = true; // for debug reasons only
5954 5954
 		if ($messageid === true || empty($messageid)) // try to figure out the message uid
5955 5955
 		{
5956
-			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
5956
+			$list = $this->getHeaders($_folderName, $_startMessage = 1, 1, 'INTERNALDATE', true, array(), null, false);
5957 5957
 			if ($list)
5958 5958
 			{
5959 5959
 				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
@@ -5993,27 +5993,27 @@  discard block
 block discarded – undo
5993 5993
 	 *				'attachments'=>$attachments,
5994 5994
 	 *				'headers'=>$headers,; boolean false on failure
5995 5995
 	 */
5996
-	static function get_mailcontent(&$mailClass,$uid,$partid='',$mailbox='', $preserveHTML = false, $addHeaderSection=true, $includeAttachments=true)
5996
+	static function get_mailcontent(&$mailClass, $uid, $partid = '', $mailbox = '', $preserveHTML = false, $addHeaderSection = true, $includeAttachments = true)
5997 5997
 	{
5998 5998
 			//echo __METHOD__." called for $uid,$partid <br>";
5999
-			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
5999
+			$headers = $mailClass->getMessageHeader($uid, $partid, true, false, $mailbox);
6000 6000
 			if (empty($headers)) return false;
6001 6001
 			// dont force retrieval of the textpart, let mailClass preferences decide
6002
-			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6002
+			$bodyParts = $mailClass->getMessageBody($uid, ($preserveHTML ? 'always_display' : 'only_if_no_text'), $partid, null, false, $mailbox);
6003 6003
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
6004
-			if ( !$preserveHTML && $bodyParts[0]['mimeType']=='text/html')
6004
+			if (!$preserveHTML && $bodyParts[0]['mimeType'] == 'text/html')
6005 6005
 			{
6006
-				foreach($bodyParts as $i => $part)
6006
+				foreach ($bodyParts as $i => $part)
6007 6007
 				{
6008
-					if ($bodyParts[$i]['mimeType']=='text/html')
6008
+					if ($bodyParts[$i]['mimeType'] == 'text/html')
6009 6009
 					{
6010
-						$bodyParts[$i]['body'] = Mail\Html::convertHTMLToText($bodyParts[$i]['body'],$bodyParts[$i]['charSet'],true,$stripalltags=true);
6011
-						$bodyParts[$i]['mimeType']='text/plain';
6010
+						$bodyParts[$i]['body'] = Mail\Html::convertHTMLToText($bodyParts[$i]['body'], $bodyParts[$i]['charSet'], true, $stripalltags = true);
6011
+						$bodyParts[$i]['mimeType'] = 'text/plain';
6012 6012
 					}
6013 6013
 				}
6014 6014
 			}
6015 6015
 			//error_log(array2string($bodyParts));
6016
-			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6016
+			$attachments = $includeAttachments ? $mailClass->getMessageAttachments($uid, $partid, null, true, false, true, $mailbox) : array();
6017 6017
 
6018 6018
 			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6019 6019
 			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
@@ -6024,7 +6024,7 @@  discard block
 block discarded – undo
6024 6024
 
6025 6025
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6026 6026
 			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
6027
-			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6027
+			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '', $preserveHTML) : '');
6028 6028
 			$message = $headdata.$message;
6029 6029
 			//echo __METHOD__.'<br>';
6030 6030
 			//_debug_array($attachments);
@@ -6040,25 +6040,25 @@  discard block
 block discarded – undo
6040 6040
 						//_debug_array($mailClass->getMessageHeader($uid, $attachment['partID']));
6041 6041
 						//_debug_array($mailClass->getMessageBody($uid,'', $attachment['partID']));
6042 6042
 						//_debug_array($mailClass->getMessageAttachments($uid, $attachment['partID']));
6043
-						$mailcontent = self::get_mailcontent($mailClass,$uid,$attachment['partID'],$mailbox);
6044
-						$headdata ='';
6043
+						$mailcontent = self::get_mailcontent($mailClass, $uid, $attachment['partID'], $mailbox);
6044
+						$headdata = '';
6045 6045
 						if ($mailcontent['headers'])
6046 6046
 						{
6047
-							$headdata = self::createHeaderInfoSection($mailcontent['headers'],'',$preserveHTML);
6047
+							$headdata = self::createHeaderInfoSection($mailcontent['headers'], '', $preserveHTML);
6048 6048
 						}
6049 6049
 						if ($mailcontent['message'])
6050 6050
 						{
6051
-							$tempname =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6051
+							$tempname = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6052 6052
 							$attachedMessages[] = array(
6053 6053
 								'type' => 'TEXT/PLAIN',
6054 6054
 								'name' => $mailcontent['subject'].'.txt',
6055 6055
 								'tmp_name' => $tempname,
6056 6056
 							);
6057
-							$tmpfile = fopen($tempname,'w');
6058
-							fwrite($tmpfile,$headdata.$mailcontent['message']);
6057
+							$tmpfile = fopen($tempname, 'w');
6058
+							fwrite($tmpfile, $headdata.$mailcontent['message']);
6059 6059
 							fclose($tmpfile);
6060 6060
 						}
6061
-						foreach($mailcontent['attachments'] as &$tmpval)
6061
+						foreach ($mailcontent['attachments'] as &$tmpval)
6062 6062
 						{
6063 6063
 							$attachedMessages[] = $tmpval;
6064 6064
 						}
@@ -6066,36 +6066,36 @@  discard block
 block discarded – undo
6066 6066
 					}
6067 6067
 					else
6068 6068
 					{
6069
-						$attachments[$num] = array_merge($attachments[$num],$mailClass->getAttachment($uid, $attachment['partID'],0,false,false));
6069
+						$attachments[$num] = array_merge($attachments[$num], $mailClass->getAttachment($uid, $attachment['partID'], 0, false, false));
6070 6070
 
6071
-						if (empty($attachments[$num]['attachment'])&&$attachments[$num]['cid'])
6071
+						if (empty($attachments[$num]['attachment']) && $attachments[$num]['cid'])
6072 6072
 						{
6073
-							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'],true);
6073
+							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'], true);
6074 6074
 							$attachments[$num]['attachment'] = $c->getContents();
6075 6075
 						}
6076 6076
 						// no attempt to convert, if we dont know about the charset
6077
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
6077
+						if (isset($attachments[$num]['charset']) && !empty($attachments[$num]['charset'])) {
6078 6078
 							// we do not try guessing the charset, if it is not set
6079 6079
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6080
-							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
6080
+							Translation::convert($attachments[$num]['attachment'], $attachments[$num]['charset']);
6081 6081
 						}
6082
-						if(in_array($attachments[$num]['name'], $file_list))
6082
+						if (in_array($attachments[$num]['name'], $file_list))
6083 6083
 						{
6084 6084
 							$dupe_count[$attachments[$num]['name']]++;
6085
-							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME) .
6086
-								' ('.($dupe_count[$attachments[$num]['name']] + 1).')' . '.' .
6085
+							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME).
6086
+								' ('.($dupe_count[$attachments[$num]['name']] + 1).')'.'.'.
6087 6087
 								pathinfo($attachments[$num]['name'], PATHINFO_EXTENSION);
6088 6088
 						}
6089 6089
 						$attachments[$num]['type'] = $attachments[$num]['mimeType'];
6090
-						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6091
-						$tmpfile = fopen($attachments[$num]['tmp_name'],'w');
6092
-						fwrite($tmpfile,$attachments[$num]['attachment']);
6090
+						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6091
+						$tmpfile = fopen($attachments[$num]['tmp_name'], 'w');
6092
+						fwrite($tmpfile, $attachments[$num]['attachment']);
6093 6093
 						fclose($tmpfile);
6094 6094
 						$file_list[] = $attachments[$num]['name'];
6095 6095
 						unset($attachments[$num]['attachment']);
6096 6096
 					}
6097 6097
 				}
6098
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
6098
+				if (is_array($attachedMessages)) $attachments = array_merge($attachments, $attachedMessages);
6099 6099
 			}
6100 6100
 			return array(
6101 6101
 					'mailaddress'=>$mailaddress,
@@ -6117,10 +6117,10 @@  discard block
 block discarded – undo
6117 6117
 	{
6118 6118
 		$c = 0;
6119 6119
 		// use the standardIdentity
6120
-		foreach($_identities as $key => $acc) {
6121
-			if ($c==0) $identity = $acc;
6120
+		foreach ($_identities as $key => $acc) {
6121
+			if ($c == 0) $identity = $acc;
6122 6122
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6123
-			if ($key==$_profile_id) $identity = $acc;
6123
+			if ($key == $_profile_id) $identity = $acc;
6124 6124
 			$c++;
6125 6125
 		}
6126 6126
 		return $identity;
@@ -6132,29 +6132,29 @@  discard block
 block discarded – undo
6132 6132
 	 * @param bool createHTML do it with HTML breaks
6133 6133
 	 * @return string a preformatted string with the information of the header worked into it
6134 6134
 	 */
6135
-	static function createHeaderInfoSection($header,$headline='', $createHTML = false)
6135
+	static function createHeaderInfoSection($header, $headline = '', $createHTML = false)
6136 6136
 	{
6137 6137
 		$headdata = null;
6138 6138
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6139
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6140
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6141
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6142
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6143
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6144
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6145
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6146
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6147
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
6139
+		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML ? "<br />" : "\n");
6140
+		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML ? "<br />" : "\n");
6141
+		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML ? "<br />" : "\n");
6142
+		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML ? "<br />" : "\n");
6143
+		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML ? "<br />" : "\n");
6144
+		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML ? "<br />" : "\n");
6145
+		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML ? "<br />" : "\n");
6146
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML ? "<br />" : "\n");
6147
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] != 'normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML ? "<br />" : "\n");
6148 6148
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6149 6149
 		if (!empty($headdata))
6150 6150
 		{
6151
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6152
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
6153
-			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6151
+			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML ? "<br />" : "\n").$headdata;
6152
+			if (empty($headline)) $headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '').$headdata;
6153
+			$headdata .= ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
6154 6154
 		}
6155 6155
 		else
6156 6156
 		{
6157
-			$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6157
+			$headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
6158 6158
 		}
6159 6159
 		return $headdata;
6160 6160
 	}
@@ -6167,8 +6167,8 @@  discard block
 block discarded – undo
6167 6167
 	 */
6168 6168
 	static function adaptSubjectForImport($subject)
6169 6169
 	{
6170
-		$subject = str_replace('$$','__',($subject?$subject:lang('(no subject)')));
6171
-		$subject = str_ireplace(array('[FWD]','[',']','{','}','<','>'),array('Fwd:',' ',' ',' ',' ',' ',' '),trim($subject));
6170
+		$subject = str_replace('$$', '__', ($subject ? $subject : lang('(no subject)')));
6171
+		$subject = str_ireplace(array('[FWD]', '[', ']', '{', '}', '<', '>'), array('Fwd:', ' ', ' ', ' ', ' ', ' ', ' '), trim($subject));
6172 6172
 		return $subject;
6173 6173
 	}
6174 6174
 
@@ -6180,15 +6180,15 @@  discard block
 block discarded – undo
6180 6180
 	static function convertAddressArrayToString($rfcAddressArray)
6181 6181
 	{
6182 6182
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($rfcAddressArray));
6183
-		$returnAddr ='';
6183
+		$returnAddr = '';
6184 6184
 		if (is_array($rfcAddressArray))
6185 6185
 		{
6186
-			foreach((array)$rfcAddressArray as $addressData) {
6186
+			foreach ((array)$rfcAddressArray as $addressData) {
6187 6187
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6188
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
6188
+				if ($addressData['MAILBOX_NAME'] == 'NIL') {
6189 6189
 					continue;
6190 6190
 				}
6191
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
6191
+				if (strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
6192 6192
 					continue;
6193 6193
 				}
6194 6194
 				if ($addressData['RFC822_EMAIL'])
@@ -6197,7 +6197,7 @@  discard block
 block discarded – undo
6197 6197
 				}
6198 6198
 				else
6199 6199
 				{
6200
-					$emailaddress = ($addressData['PERSONAL_NAME']?$addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>':$addressData['EMAIL']);
6200
+					$emailaddress = ($addressData['PERSONAL_NAME'] ? $addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>' : $addressData['EMAIL']);
6201 6201
 					$addressObjectA = self::parseAddressList($emailaddress);
6202 6202
 				}
6203 6203
 				$addressObject = $addressObjectA[0];
@@ -6206,10 +6206,10 @@  discard block
 block discarded – undo
6206 6206
 				//$mb =(string)$addressObject->mailbox;
6207 6207
 				//$h = (string)$addressObject->host;
6208 6208
 				//$p = (string)$addressObject->personal;
6209
-				$returnAddr .= (strlen($returnAddr)>0?',':'');
6209
+				$returnAddr .= (strlen($returnAddr) > 0 ? ',' : '');
6210 6210
 				//error_log(__METHOD__.' ('.__LINE__.') '.$p.' <'.$mb.'@'.$h.'>');
6211 6211
 				$buff = imap_rfc822_write_address($addressObject->mailbox, Horde_Idna::decode($addressObject->host), $addressObject->personal);
6212
-				$buff = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$buff);
6212
+				$buff = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $buff);
6213 6213
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Address: '.$returnAddr);
6214 6214
 				$returnAddr .= $buff;
6215 6215
 			}
@@ -6217,8 +6217,8 @@  discard block
 block discarded – undo
6217 6217
 		else
6218 6218
 		{
6219 6219
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6220
-			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6221
-			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6220
+			$rfcAddressArray = self::decode_header($rfcAddressArray, true);
6221
+			$rfcAddressArray = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $rfcAddressArray);
6222 6222
 			if (is_string($rfcAddressArray)) return $rfcAddressArray;
6223 6223
 		}
6224 6224
 		return $returnAddr;
@@ -6232,12 +6232,12 @@  discard block
 block discarded – undo
6232 6232
 	 * @param string &$err error-message on error
6233 6233
 	 * @return string/boolean merged content or false on error
6234 6234
 	 */
6235
-	static function merge($content,$ids,$mimetype='')
6235
+	static function merge($content, $ids, $mimetype = '')
6236 6236
 	{
6237 6237
 		$mergeobj = new Contacts\Merge();
6238 6238
 
6239
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
6240
-		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6239
+		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ? 'text/plain' : 'text/html');
6240
+		$rv = $mergeobj->merge_string($content, $ids, $err = '', $mimetype, array(), self::$displayCharset);
6241 6241
 		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6242 6242
 		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
6243 6243
 		return $rv;
@@ -6279,12 +6279,12 @@  discard block
 block discarded – undo
6279 6279
 		else
6280 6280
 			settype($bytes, 'integer');
6281 6281
 
6282
-		return $bytes . ' ' . $type ;
6282
+		return $bytes.' '.$type;
6283 6283
 	}
6284 6284
 
6285 6285
 	static function detect_qp(&$sting) {
6286 6286
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6287
-		return preg_match("$needle",$string);
6287
+		return preg_match("$needle", $string);
6288 6288
 	}
6289 6289
 
6290 6290
 	/**
@@ -6297,11 +6297,11 @@  discard block
 block discarded – undo
6297 6297
 	 * @param string $_methodNline - Information where the log was taken
6298 6298
 	 * @return void
6299 6299
 	 */
6300
-	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6300
+	static function logRunTimes($_starttime, $_endtime = null, $_message = '', $_methodNline = '')
6301 6301
 	{
6302 6302
 		if (is_null($_endtime)) $_endtime = microtime(true);
6303 6303
 		$usagetime = microtime(true) - $_starttime;
6304
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
6304
+		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime, 5).'(s) '.($_message ? 'Details:'.$_message : ''));
6305 6305
 	}
6306 6306
 
6307 6307
 	/**
@@ -6314,9 +6314,9 @@  discard block
 block discarded – undo
6314 6314
 	 *
6315 6315
 	 * @throws Exception\WrongUserinput
6316 6316
 	 */
6317
-	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6317
+	static function checkFileBasics(&$_formData, $IDtoAddToFileName = '', $reqMimeType = 'message/rfc822')
6318 6318
 	{
6319
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6319
+		if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6320 6320
 
6321 6321
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6322 6322
 		$importfailed = $tmpFileName = false;
@@ -6326,7 +6326,7 @@  discard block
 block discarded – undo
6326 6326
 			$importfailed = true;
6327 6327
 			$alert_msg .= lang("Empty file %1 ignored.", $_formData['name']);
6328 6328
 		}
6329
-		elseif (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6329
+		elseif (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6330 6330
 			realpath(dirname($_formData['file'])) == realpath($GLOBALS['egw_info']['server']['temp_dir']))
6331 6331
 		{
6332 6332
 			// ensure existance of eGW temp dir
@@ -6334,7 +6334,7 @@  discard block
 block discarded – undo
6334 6334
 			// and different from any other temp file location set in php.ini
6335 6335
 			if (!file_exists($GLOBALS['egw_info']['server']['temp_dir']))
6336 6336
 			{
6337
-				@mkdir($GLOBALS['egw_info']['server']['temp_dir'],0700);
6337
+				@mkdir($GLOBALS['egw_info']['server']['temp_dir'], 0700);
6338 6338
 			}
6339 6339
 
6340 6340
 			// if we were NOT able to create this temp directory, then make an ERROR report
@@ -6361,14 +6361,14 @@  discard block
 block discarded – undo
6361 6361
 			// maybe its application/octet-stream -> this may mean that we could not determine the type
6362 6362
 			// so we check for the suffix too
6363 6363
 			// trust vfs mime-types, trust the mimetype if it contains a method
6364
-			if ((substr($_formData['file'],0,6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'],'method=')===false)
6364
+			if ((substr($_formData['file'], 0, 6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'], 'method=') === false)
6365 6365
 			{
6366
-				$buff = explode('.',$_formData['name']);
6366
+				$buff = explode('.', $_formData['name']);
6367 6367
 				$suffix = '';
6368 6368
 				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6369 6369
 				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
6370 6370
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6371
-					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6371
+					(strlen(trim($_formData['type'])) == 0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6372 6372
 				{
6373 6373
 					error_log(__METHOD__.' ('.__LINE__.') '.' Data:'.array2string($_formData));
6374 6374
 					error_log(__METHOD__.' ('.__LINE__.') '.' Form reported Mimetype:'.$_formData['type'].' but seems to be:'.$sfxMimeType);
@@ -6383,13 +6383,13 @@  discard block
 block discarded – undo
6383 6383
 			if ($reqMimeType)
6384 6384
 			{
6385 6385
 				// so if PHP did not pass any file_type info, then substitute the rfc default value
6386
-				if (substr(strtolower(trim($_formData['type'])),0,strlen($mime_type_default)) != $mime_type_default)
6386
+				if (substr(strtolower(trim($_formData['type'])), 0, strlen($mime_type_default)) != $mime_type_default)
6387 6387
 				{
6388 6388
 					if (!(strtolower(trim($_formData['type'])) == "application/octet-stream" && $sfxMimeType == $reqMimeType))
6389 6389
 					{
6390 6390
 						//error_log("Message rejected, no message/rfc. Is:".$_formData['type']);
6391 6391
 						$importfailed = true;
6392
-						$alert_msg .= lang("File rejected, no %2. Is:%1",$_formData['type'],$reqMimeType);
6392
+						$alert_msg .= lang("File rejected, no %2. Is:%1", $_formData['type'], $reqMimeType);
6393 6393
 					}
6394 6394
 					if ((strtolower(trim($_formData['type'])) != $reqMimeType && $sfxMimeType == $reqMimeType))
6395 6395
 					{
@@ -6398,17 +6398,17 @@  discard block
 block discarded – undo
6398 6398
 				}
6399 6399
 			}
6400 6400
 			// as FreeBSD seems to have problems with the generated temp names we append some more random stuff
6401
-			$randomString = chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90));
6401
+			$randomString = chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90));
6402 6402
 			$tmpFileName = $GLOBALS['egw_info']['user']['account_id'].
6403 6403
 				trim($IDtoAddToFileName).basename($_formData['file']).'_'.$randomString;
6404 6404
 
6405
-			if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs')
6405
+			if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs')
6406 6406
 			{
6407
-				$tmpFileName = $_formData['file'];	// no need to store it somewhere
6407
+				$tmpFileName = $_formData['file']; // no need to store it somewhere
6408 6408
 			}
6409 6409
 			elseif (is_uploaded_file($_formData['file']))
6410 6410
 			{
6411
-				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);	// requirement for safe_mode!
6411
+				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName); // requirement for safe_mode!
6412 6412
 			}
6413 6413
 			else
6414 6414
 			{
@@ -6417,7 +6417,7 @@  discard block
 block discarded – undo
6417 6417
 		} else {
6418 6418
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6419 6419
 			$importfailed = true;
6420
-			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
6420
+			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.", $_formData['name']);
6421 6421
 		}
6422 6422
 		if ($importfailed == true)
6423 6423
 		{
@@ -6425,7 +6425,7 @@  discard block
 block discarded – undo
6425 6425
 		}
6426 6426
 		else
6427 6427
 		{
6428
-			if (parse_url($tmpFileName,PHP_URL_SCHEME) == 'vfs')
6428
+			if (parse_url($tmpFileName, PHP_URL_SCHEME) == 'vfs')
6429 6429
 			{
6430 6430
 				Vfs::load_wrapper('vfs');
6431 6431
 			}
@@ -6450,7 +6450,7 @@  discard block
 block discarded – undo
6450 6450
 		$images = null;
6451 6451
 		if (preg_match_all("/(src|background)=\"(.*)\"/Ui", $_html2parse, $images) && isset($images[2]))
6452 6452
 		{
6453
-			foreach($images[2] as $i => $url)
6453
+			foreach ($images[2] as $i => $url)
6454 6454
 			{
6455 6455
 				//$isData = false;
6456 6456
 				$basedir = $data = '';
@@ -6462,20 +6462,20 @@  discard block
 block discarded – undo
6462 6462
 					$filename = basename($url);
6463 6463
 					if (($directory = dirname($url)) == '.') $directory = '';
6464 6464
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6465
-					$mimeType  = MimeMagic::ext2mime($ext);
6466
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
6465
+					$mimeType = MimeMagic::ext2mime($ext);
6466
+					if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
6467 6467
 					$myUrl = $directory.$filename;
6468
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
6468
+					if ($myUrl[0] == '/') // local path -> we only allow path's that are available via http/https (or vfs)
6469 6469
 					{
6470
-						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6470
+						$basedir = ($_SERVER['HTTPS'] ? 'https://' : 'http://'.$_SERVER['HTTP_HOST']);
6471 6471
 					}
6472 6472
 					// use vfs instead of url containing webdav.php
6473 6473
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6474 6474
 					// webdav.php urls as vfs
6475
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6475
+					if (strpos($myUrl, '/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6476 6476
 					{
6477 6477
 						Vfs::load_wrapper('vfs');
6478
-						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6478
+						list(,$myUrl) = explode('/webdav.php', $myUrl, 2);
6479 6479
 						$basedir = 'vfs://default';
6480 6480
 						$needTempFile = false;
6481 6481
 					}
@@ -6488,11 +6488,11 @@  discard block
 block discarded – undo
6488 6488
 						// Strips the url and store it into a temp for further procss
6489 6489
 						$tmp_url = html_entity_decode($myUrl);
6490 6490
 
6491
-						parse_str(parse_url($tmp_url, PHP_URL_QUERY),$URI_params);
6491
+						parse_str(parse_url($tmp_url, PHP_URL_QUERY), $URI_params);
6492 6492
 						if ($URI_params['mailbox'] && $URI_params['uid'] && $URI_params['cid'])
6493 6493
 						{
6494 6494
 							$mail_bo->reopen(base64_decode($URI_params['mailbox']));
6495
-							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']),base64_decode($URI_params['partID']),true);
6495
+							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']), base64_decode($URI_params['partID']), true);
6496 6496
 							$mail_bo->closeConnection();
6497 6497
 							if ($attachment)
6498 6498
 							{
@@ -6503,32 +6503,32 @@  discard block
 block discarded – undo
6503 6503
 						}
6504 6504
 					}
6505 6505
 
6506
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6507
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6506
+					if (strlen($basedir) > 1 && substr($basedir, -1) != '/' && $myUrl[0] != '/') { $basedir .= '/'; }
6507
+					if ($needTempFile && !$attachment && substr($myUrl, 0, 4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6508 6508
 				}
6509
-				if (substr($url,0,strlen('data:'))=='data:')
6509
+				if (substr($url, 0, strlen('data:')) == 'data:')
6510 6510
 				{
6511 6511
 					//error_log(__METHOD__.' ('.__LINE__.') '.' -> '.$i.': '.array2string($images[$i]));
6512 6512
 					// we only support base64 encoded data
6513
-					$tmp = substr($url,strlen('data:'));
6514
-					list($mimeType,$data_base64) = explode(';base64,',$tmp);
6513
+					$tmp = substr($url, strlen('data:'));
6514
+					list($mimeType, $data_base64) = explode(';base64,', $tmp);
6515 6515
 					$data = base64_decode($data_base64);
6516 6516
 					// FF currently does NOT add any mime-type
6517 6517
 					if (strtolower(substr($mimeType, 0, 6)) != 'image/')
6518 6518
 					{
6519 6519
 						$mimeType = MimeMagic::analyze_data($data);
6520 6520
 					}
6521
-					list($what,$exactly) = explode('/',$mimeType);
6521
+					list($what, $exactly) = explode('/', $mimeType);
6522 6522
 					$needTempFile = true;
6523
-					$filename = ($what?$what:'data').$imageC++.'.'.$exactly;
6523
+					$filename = ($what ? $what : 'data').$imageC++.'.'.$exactly;
6524 6524
 				}
6525 6525
 				if ($data || $needTempFile === false)
6526 6526
 				{
6527 6527
 					if ($needTempFile)
6528 6528
 					{
6529
-						$attachment_file =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6530
-						$tmpfile = fopen($attachment_file,'w');
6531
-						fwrite($tmpfile,$data);
6529
+						$attachment_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6530
+						$tmpfile = fopen($attachment_file, 'w');
6531
+						fwrite($tmpfile, $data);
6532 6532
 						fclose($tmpfile);
6533 6533
 					}
6534 6534
 					else
@@ -6539,7 +6539,7 @@  discard block
 block discarded – undo
6539 6539
 					// (or similar) in all cases (when cut&paste). This may lead to more attached files, in case
6540 6540
 					// we use the same image multiple times, but, if we do this, we should try to detect that
6541 6541
 					// on upload. filename itself is not sufficient to determine the sameness of images
6542
-					$cid = 'cid:' . md5($attachment_file);
6542
+					$cid = 'cid:'.md5($attachment_file);
6543 6543
 					if ($_mailObject->AddEmbeddedImage($attachment_file, substr($cid, 4), urldecode($filename), $mimeType) !== null)
6544 6544
 					{
6545 6545
 						//$_html2parse = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $_html2parse);
@@ -6561,10 +6561,10 @@  discard block
 block discarded – undo
6561 6561
 	 * @param string& $importID ID for the imported message, used by attachments to identify them unambiguously
6562 6562
 	 * @return mixed array of messages with success and failed messages or exception
6563 6563
 	 */
6564
-	function importMessageToMergeAndSend(Storage\Merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID='')
6564
+	function importMessageToMergeAndSend(Storage\Merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID = '')
6565 6565
 	{
6566 6566
 		$importfailed = false;
6567
-		$processStats = array('success'=>array(),'failed'=>array());
6567
+		$processStats = array('success'=>array(), 'failed'=>array());
6568 6568
 		if (empty($SendAndMergeTocontacts))
6569 6569
 		{
6570 6570
 			$importfailed = true;
@@ -6605,7 +6605,7 @@  discard block
 block discarded – undo
6605 6605
 				$_folder = $this->getSentFolder();
6606 6606
 			}
6607 6607
 			$delimiter = $this->getHierarchyDelimiter();
6608
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
6608
+			if ($_folder == 'INBOX'.$delimiter) $_folder = 'INBOX';
6609 6609
 			if ($importfailed === false)
6610 6610
 			{
6611 6611
 				$Subject = $mailObject->getHeader('Subject');
@@ -6623,9 +6623,9 @@  discard block
 block discarded – undo
6623 6623
 				{
6624 6624
 					$mailObject->clearReplyTos();
6625 6625
 					$activeMailProfiles = $this->mail->getAccountIdentities($this->profileID);
6626
-					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6626
+					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6627 6627
 
6628
-					$mailObject->addReplyTo(Horde_Idna::encode($activeMailProfile['ident_email']),Mail::generateIdentityString($activeMailProfile,false));
6628
+					$mailObject->addReplyTo(Horde_Idna::encode($activeMailProfile['ident_email']), Mail::generateIdentityString($activeMailProfile, false));
6629 6629
 				}
6630 6630
 				foreach ($SendAndMergeTocontacts as $k => $val)
6631 6631
 				{
@@ -6639,12 +6639,12 @@  discard block
 block discarded – undo
6639 6639
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6640 6640
 
6641 6641
 						// Parse destinations for placeholders
6642
-						foreach(Mailer::$type2header as $type => $h)
6642
+						foreach (Mailer::$type2header as $type => $h)
6643 6643
 						{
6644 6644
 							//error_log('ID ' . $val . ' ' .$type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset));
6645
-							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6646
-							$mailObject->addAddress($merged,'',$type);
6647
-							if($type == 'to')
6645
+							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6646
+							$mailObject->addAddress($merged, '', $type);
6647
+							if ($type == 'to')
6648 6648
 							{
6649 6649
 								$email = $merged;
6650 6650
 							}
@@ -6657,26 +6657,26 @@  discard block
 block discarded – undo
6657 6657
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ID:'.$val.' Data:'.array2string($contact));
6658 6658
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6659 6659
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6660
-							if($email)
6660
+							if ($email)
6661 6661
 							{
6662 6662
 								$mailObject->addAddress(Horde_Idna::encode($email), $nfn);
6663 6663
 							}
6664 6664
 						}
6665 6665
 
6666 6666
 						$activeMailProfiles = $this->getAccountIdentities($this->profileID);
6667
-						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6667
+						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6668 6668
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($activeMailProfile));
6669 6669
 						$mailObject->setFrom($activeMailProfile['ident_email'],
6670
-							self::generateIdentityString($activeMailProfile,false));
6670
+							self::generateIdentityString($activeMailProfile, false));
6671 6671
 
6672 6672
 						$mailObject->removeHeader('Message-ID');
6673 6673
 						$mailObject->removeHeader('Date');
6674 6674
 						$mailObject->clearCustomHeaders();
6675 6675
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6676 6676
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6677
-						if($text_body) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6677
+						if ($text_body) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset), array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6678 6678
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6679
-						if($html_body) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6679
+						if ($html_body) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset), array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6680 6680
 
6681 6681
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6682 6682
 						// set a higher timeout for big messages
@@ -6685,7 +6685,7 @@  discard block
 block discarded – undo
6685 6685
 						try {
6686 6686
 							$mailObject->send();
6687 6687
 						}
6688
-						catch(Exception $e) {
6688
+						catch (Exception $e) {
6689 6689
 							$sendOK = false;
6690 6690
 							$errorInfo = $e->getMessage();
6691 6691
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
@@ -6699,41 +6699,41 @@  discard block
 block discarded – undo
6699 6699
 						$mailObject->clearCustomHeaders();
6700 6700
 
6701 6701
 						// Parse destinations for placeholders
6702
-						foreach(Mailer::$type2header as $type => $h)
6702
+						foreach (Mailer::$type2header as $type => $h)
6703 6703
 						{
6704
-							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6704
+							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6705 6705
 							//error_log($type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$merged);
6706
-							$mailObject->addAddress(trim($merged,'"'),'',$type);
6706
+							$mailObject->addAddress(trim($merged, '"'), '', $type);
6707 6707
 						}
6708 6708
 
6709 6709
 						// No addresses from placeholders?  Treat it as just a contact ID
6710
-						if (count($mailObject->getAddresses('to',true)) == 0 &&
6710
+						if (count($mailObject->getAddresses('to', true)) == 0 &&
6711 6711
 							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
6712 6712
 						{
6713 6713
 							$contact = $bo_merge->contacts->read($val);
6714 6714
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6715 6715
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6716 6716
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6717
-							if($email)
6717
+							if ($email)
6718 6718
 							{
6719 6719
 								$mailObject->addAddress(Horde_Idna::encode($email), $nfn);
6720 6720
 							}
6721 6721
 						}
6722 6722
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6723 6723
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6724
-						if (!empty($Body)) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6724
+						if (!empty($Body)) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset), array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6725 6725
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6726
-						if (!empty($AltBody)) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6726
+						if (!empty($AltBody)) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset), array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6727 6727
 						$_folder = $this->getDraftFolder();
6728 6728
 					}
6729 6729
 					if ($sendOK || $openAsDraft)
6730 6730
 					{
6731
-						if ($this->folderExists($_folder,true))
6731
+						if ($this->folderExists($_folder, true))
6732 6732
 						{
6733
-						    if($this->isSentFolder($_folder))
6733
+						    if ($this->isSentFolder($_folder))
6734 6734
 							{
6735 6735
 						        $flags = '\\Seen';
6736
-						    } elseif($this->isDraftFolder($_folder)) {
6736
+						    } elseif ($this->isDraftFolder($_folder)) {
6737 6737
 						        $flags = '\\Draft';
6738 6738
 						    } else {
6739 6739
 						        $flags = '';
@@ -6741,7 +6741,7 @@  discard block
 block discarded – undo
6741 6741
 							$savefailed = false;
6742 6742
 							try
6743 6743
 							{
6744
-								$messageUid =$this->appendMessage($_folder,
6744
+								$messageUid = $this->appendMessage($_folder,
6745 6745
 									$mailObject->getRaw(),
6746 6746
 									null,
6747 6747
 									$flags);
@@ -6749,10 +6749,10 @@  discard block
 block discarded – undo
6749 6749
 							catch (\Exception\WrongUserinput $e)
6750 6750
 							{
6751 6751
 								$savefailed = true;
6752
-								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3",$Subject,$_folder,$e->getMessage());
6752
+								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3", $Subject, $_folder, $e->getMessage());
6753 6753
 							}
6754 6754
 							// no send, save successful, and message_uid present
6755
-							if ($savefailed===false && $messageUid && is_null($sendOK))
6755
+							if ($savefailed === false && $messageUid && is_null($sendOK))
6756 6756
 							{
6757 6757
 								$importID = $messageUid;
6758 6758
 								$openComposeWindow = true;
@@ -6761,20 +6761,20 @@  discard block
 block discarded – undo
6761 6761
 						else
6762 6762
 						{
6763 6763
 							$savefailed = true;
6764
-							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.",$Subject,$_folder);
6764
+							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.", $Subject, $_folder);
6765 6765
 						}
6766 6766
 						if ($sendOK)
6767 6767
 						{
6768
-							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed?' but failed to store to Folder:'.$_folder:'');
6768
+							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed ? ' but failed to store to Folder:'.$_folder : '');
6769 6769
 						}
6770 6770
 						else
6771 6771
 						{
6772
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6772
+							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6773 6773
 						}
6774 6774
 					}
6775
-					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
6775
+					if (!is_null($sendOK) && $sendOK === false && is_null($openComposeWindow))
6776 6776
 					{
6777
-						$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6777
+						$processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6778 6778
 					}
6779 6779
 				}
6780 6780
 			}
@@ -6844,19 +6844,18 @@  discard block
 block discarded – undo
6844 6844
 			//error_log(__METHOD__.__LINE__.':'.array2string($structure));
6845 6845
 
6846 6846
 			// unfortunately parseMessage does NOT return parsed headers (we assume header is shorter then 8k)
6847
-			$start = is_string($message) ? substr($message, 0, 8192) :
6848
-				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6847
+			$start = is_string($message) ? substr($message, 0, 8192) : (fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6849 6848
 
6850 6849
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6851
-			if ($length===false) $length = strlen($start);
6852
-			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6850
+			if ($length === false) $length = strlen($start);
6851
+			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0, $length));
6853 6852
 
6854
-			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
6853
+			foreach ($headers->toArray(array('nowrap' => true)) as $header => $value)
6855 6854
 			{
6856
-				foreach((array)$value as $n => $val)
6855
+				foreach ((array)$value as $n => $val)
6857 6856
 				{
6858 6857
 					$overwrite = !$n;
6859
-					switch($header)
6858
+					switch ($header)
6860 6859
 					{
6861 6860
 						case 'Content-Transfer-Encoding':
6862 6861
 							//as we parse the message and this sets the part with a Content-Transfer-Encoding, we
@@ -6877,7 +6876,7 @@  discard block
 block discarded – undo
6877 6876
 		}
6878 6877
 		else
6879 6878
 		{
6880
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
6879
+			if (($type = gettype($message)) == 'object') $type = get_class($message);
6881 6880
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
6882 6881
 		}
6883 6882
 	}
@@ -6891,50 +6890,50 @@  discard block
 block discarded – undo
6891 6890
 	 * @param string $default_domain
6892 6891
 	 * @return Horde_Mail_Rfc822_List iteratable Horde_Mail_Rfc822_Address objects with attributes mailbox, host, personal and valid
6893 6892
 	 */
6894
-	public static function parseAddressList($addresses, $default_domain=null)
6893
+	public static function parseAddressList($addresses, $default_domain = null)
6895 6894
 	{
6896 6895
 		$rfc822 = new Horde_Mail_Rfc822();
6897 6896
 		$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
6898 6897
 		//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count.function_backtrace());
6899
-		if ((empty($ret) || $ret->count()==0)&& is_string($addresses) && strlen($addresses)>0)
6898
+		if ((empty($ret) || $ret->count() == 0) && is_string($addresses) && strlen($addresses) > 0)
6900 6899
 		{
6901 6900
 			$matches = array();
6902
-			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
6901
+			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/", $addresses, $matches);
6903 6902
 			//error_log(__METHOD__.__LINE__.array2string($matches));
6904
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
6905
-			$addresses = implode(',',$matches[0]);
6903
+			foreach ($matches[0] as &$match) {$match = trim($match, ', '); }
6904
+			$addresses = implode(',', $matches[0]);
6906 6905
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
6907 6906
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
6908 6907
 			//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count);
6909 6908
 		}
6910
-		$previousFailed=false;
6909
+		$previousFailed = false;
6911 6910
 		$ret2 = new Horde_Mail_Rfc822_List();
6912 6911
 		// handle known problems on emailaddresses
6913
-		foreach($ret as $i => $adr)
6912
+		foreach ($ret as $i => $adr)
6914 6913
 		{
6915 6914
 			//mailaddresses enclosed in single quotes like '[email protected]' show up as 'me as mailbox and you.com' as host
6916
-			if ($adr->mailbox && stripos($adr->mailbox,"'")== 0 &&
6917
-					$adr->host && stripos($adr->host,"'")== (strlen($adr->host) -1))
6915
+			if ($adr->mailbox && stripos($adr->mailbox, "'") == 0 &&
6916
+					$adr->host && stripos($adr->host, "'") == (strlen($adr->host) - 1))
6918 6917
 			{
6919
-				$adr->mailbox = str_replace("'","",$adr->mailbox);
6920
-				$adr->host = str_replace("'","",$adr->host);
6918
+				$adr->mailbox = str_replace("'", "", $adr->mailbox);
6919
+				$adr->host = str_replace("'", "", $adr->host);
6921 6920
 			}
6922 6921
 			// no mailbox or host part as 'Xr\xc3\xa4hlyz, User <[email protected]>' is parsed as 2 addresses separated by ','
6923 6922
 			//#'Xr\xc3\xa4hlyz, User <[email protected]>'
6924 6923
 			//#Horde_Mail_Rfc822_List Object([_data:protected] => Array(
6925 6924
 			//[0] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => Xr\xc3\xa4hlyz[_host:protected] => [_personal:protected] => )
6926 6925
 			//[1] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => mailboxpart1.mailboxpart2[_host:protected] => youthost.com[_personal:protected] => User))[_filter:protected] => Array()[_ptr:protected] => )#2#,
6927
-			if (strlen($adr->mailbox)==0||strlen($adr->host)==0)
6926
+			if (strlen($adr->mailbox) == 0 || strlen($adr->host) == 0)
6928 6927
 			{
6929
-				$remember = ($adr->mailbox?$adr->mailbox:($adr->host?$adr->host:''));
6930
-				$previousFailed=true;
6928
+				$remember = ($adr->mailbox ? $adr->mailbox : ($adr->host ? $adr->host : ''));
6929
+				$previousFailed = true;
6931 6930
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
6932 6931
 			}
6933 6932
 			else
6934 6933
 			{
6935
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
6934
+				if ($previousFailed && $remember) $adr->personal = $remember.' '.$adr->personal;
6936 6935
 				$remember = '';
6937
-				$previousFailed=false;
6936
+				$previousFailed = false;
6938 6937
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
6939 6938
 				$ret2->add($adr);
6940 6939
 			}
@@ -6950,7 +6949,7 @@  discard block
 block discarded – undo
6950 6949
 	 * @param string $_folder
6951 6950
 	 * @return boolean
6952 6951
 	 */
6953
-	function sendMDN($uid,$_folder)
6952
+	function sendMDN($uid, $_folder)
6954 6953
 	{
6955 6954
 		$acc = Mail\Account::read($this->profileID);
6956 6955
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
@@ -6980,7 +6979,7 @@  discard block
 block discarded – undo
6980 6979
 	 */
6981 6980
 	function addAccount($_hookValues)
6982 6981
 	{
6983
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
6982
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
6984 6983
 
6985 6984
 	}
6986 6985
 
@@ -6994,7 +6993,7 @@  discard block
 block discarded – undo
6994 6993
 	 */
6995 6994
 	function deleteAccount($_hookValues)
6996 6995
 	{
6997
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
6996
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
6998 6997
 
6999 6998
 	}
7000 6999
 
@@ -7008,7 +7007,7 @@  discard block
 block discarded – undo
7008 7007
 	 */
7009 7008
 	function updateAccount($_hookValues)
7010 7009
 	{
7011
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7010
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7012 7011
 
7013 7012
 	}
7014 7013
 }
Please login to merge, or discard this patch.
Braces   +1767 added lines, -522 removed lines patch added patch discarded remove patch
@@ -198,7 +198,10 @@  discard block
 block discarded – undo
198 198
 	public static function getInstance($_restoreSession=true, &$_profileID=0, $_validate=true, $_oldImapServerObject=false, $_reuseCache=null)
199 199
 	{
200 200
 		//$_restoreSession=false;
201
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
201
+		if (is_null($_reuseCache))
202
+		{
203
+			$_reuseCache = $_restoreSession;
204
+		}
202 205
 		//error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.'/'.Mail\Account::get_default_acc_id().' for user:'.$GLOBALS['egw_info']['user']['account_lid'].' called from:'.function_backtrace());
203 206
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_oldImapServerObject));
204 207
 		if ($_oldImapServerObject instanceof Mail\Imap)
@@ -224,9 +227,15 @@  discard block
 block discarded – undo
224 227
 			{
225 228
 				$profileID = Mail\Account::get_default_acc_id();
226 229
 			}
227
-			if ($profileID!=$_profileID) $_restoreSession==false;
230
+			if ($profileID!=$_profileID)
231
+			{
232
+				$_restoreSession==false;
233
+			}
228 234
 			$_profileID=$profileID;
229
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
235
+			if (self::$debug)
236
+			{
237
+				error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
238
+			}
230 239
 		}
231 240
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
232 241
 		if ($_oldImapServerObject===true)
@@ -265,7 +274,8 @@  discard block
 block discarded – undo
265 274
 				// TODO: merge mailprefs into userprefs, for easy treatment
266 275
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
267 276
 				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
268
-			} catch (\Exception $e)
277
+			}
278
+			catch (\Exception $e)
269 279
 			{
270 280
 				$newprofileID = Mail\Account::get_default_acc_id();
271 281
 				// try loading the default profile for the user
@@ -283,9 +293,15 @@  discard block
 block discarded – undo
283 293
 			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
284 294
 		}
285 295
 		self::$instances[$_profileID]->profileID = $_profileID;
286
-		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new Horde_Idna;
296
+		if (!isset(self::$instances[$_profileID]->idna2))
297
+		{
298
+			self::$instances[$_profileID]->idna2 = new Horde_Idna;
299
+		}
287 300
 		//if ($_profileID==0); error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID);
288
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
301
+		if (is_null(self::$mailConfig))
302
+		{
303
+			self::$mailConfig = Config::read('mail');
304
+		}
289 305
 		return self::$instances[$_profileID];
290 306
 	}
291 307
 
@@ -310,14 +326,20 @@  discard block
 block discarded – undo
310 326
 			}
311 327
 			catch (\Exception $e)
312 328
 			{
313
-				if ($_profileID != Mail\Account::get_default_acc_id()) $_profileID = Mail\Account::get_default_acc_id();
329
+				if ($_profileID != Mail\Account::get_default_acc_id())
330
+				{
331
+					$_profileID = Mail\Account::get_default_acc_id();
332
+				}
314 333
 				error_log(__METHOD__.__LINE__.' '.$e->getMessage());
315 334
 				return false;
316 335
 			}
317 336
 		}
318 337
 		if ($oldProfileID != $_profileID)
319 338
 		{
320
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
339
+			if ($oldProfileID && $_profileID==0)
340
+			{
341
+				$_profileID = $oldProfileID;
342
+			}
321 343
 			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
322 344
 			// save prefs
323 345
 			$GLOBALS['egw']->preferences->save_repository(true);
@@ -347,11 +369,17 @@  discard block
 block discarded – undo
347 369
 				{
348 370
 					return $_acc_id;
349 371
 				}
350
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
372
+				if (self::$debug)
373
+				{
374
+					error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
375
+				}
351 376
 			}
352 377
 			catch (\Exception $e) {
353 378
 				unset($e);
354
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT found!");
379
+				if (self::$debug)
380
+				{
381
+					error_log(__METHOD__."($_acc_id) account NOT found!");
382
+				}
355 383
 			}
356 384
 		}
357 385
 		// no account specified or specified account not found or not valid
@@ -360,11 +388,17 @@  discard block
 block discarded – undo
360 388
 		{
361 389
 			if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap())
362 390
 			{
363
-				if (self::$debug && $_acc_id) error_log(__METHOD__."($_acc_id) using $acc_id instead");
391
+				if (self::$debug && $_acc_id)
392
+				{
393
+					error_log(__METHOD__."($_acc_id) using $acc_id instead");
394
+				}
364 395
 				return $acc_id;
365 396
 			}
366 397
 		}
367
-		if (self::$debug) error_log(__METHOD__."($_acc_id) NO valid account found!");
398
+		if (self::$debug)
399
+		{
400
+			error_log(__METHOD__."($_acc_id) NO valid account found!");
401
+		}
368 402
 		return 0;
369 403
 	}
370 404
 
@@ -380,10 +414,19 @@  discard block
 block discarded – undo
380 414
 	 */
381 415
 	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
382 416
 	{
383
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
384
-		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
417
+		if (is_null($_reuseCache))
418
+		{
419
+			$_reuseCache = $_restoreSession;
420
+		}
421
+		if (!empty($_displayCharset))
422
+		{
423
+			self::$displayCharset = $_displayCharset;
424
+		}
385 425
 		// not nummeric, we assume we only want an empty class object
386
-		if (!is_numeric($_profileID)) return true;
426
+		if (!is_numeric($_profileID))
427
+		{
428
+			return true;
429
+		}
387 430
 		if ($_restoreSession)
388 431
 		{
389 432
 			//error_log(__METHOD__." Session restore ".function_backtrace());
@@ -398,7 +441,10 @@  discard block
 block discarded – undo
398 441
 			$firstMessage = $this->sessionData['previewMessage'];
399 442
 			$this->sessionData = array();
400 443
 		}
401
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
444
+		if (!$_reuseCache)
445
+		{
446
+			$this->forcePrefReload($_profileID,!$_reuseCache);
447
+		}
402 448
 		try
403 449
 		{
404 450
 			$this->profileID = self::validateProfileID($_profileID);
@@ -422,7 +468,10 @@  discard block
 block discarded – undo
422 468
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
423 469
 		}
424 470
 
425
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
471
+		if (is_null(self::$mailConfig))
472
+		{
473
+			self::$mailConfig = Config::read('mail');
474
+		}
426 475
 	}
427 476
 
428 477
 	/**
@@ -451,7 +500,10 @@  discard block
 block discarded – undo
451 500
 		// unset the mail_preferences session object, to force the reload/rebuild
452 501
 		Cache::setSession('mail','mail_preferences',serialize(array()));
453 502
 		Cache::setSession('emailadmin','session_data',serialize(array()));
454
-		if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id);
503
+		if ($_resetFolderObjects)
504
+		{
505
+			self::resetFolderObjectCache($_profile_id);
506
+		}
455 507
 	}
456 508
 
457 509
 	/**
@@ -461,7 +513,10 @@  discard block
 block discarded – undo
461 513
 	{
462 514
 		$this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
463 515
 		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
464
-		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
516
+		if (!empty(self::$activeFolderCache[$this->profileID]))
517
+		{
518
+			$this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
519
+		}
465 520
 	}
466 521
 
467 522
 	/**
@@ -470,7 +525,10 @@  discard block
 block discarded – undo
470 525
 	function saveSessionData()
471 526
 	{
472 527
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
473
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
528
+		if (!empty($this->sessionData['mailbox']))
529
+		{
530
+			self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
531
+		}
474 532
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
475 533
 		{
476 534
 			Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
@@ -491,8 +549,14 @@  discard block
 block discarded – undo
491 549
 	 */
492 550
 	static function unsetCachedObjects($_profileID=null)
493 551
 	{
494
-		if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id();
495
-		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
552
+		if (is_null($_profileID))
553
+		{
554
+			$_profileID = Mail\Account::get_default_acc_id();
555
+		}
556
+		if (is_array($_profileID) && $_profileID['account_id'])
557
+		{
558
+			$account_id = $_profileID['account_id'];
559
+		}
496 560
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
497 561
 		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
498 562
 		{
@@ -525,7 +589,10 @@  discard block
 block discarded – undo
525 589
 				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
526 590
 			}
527 591
 
528
-			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
592
+			if (isset(self::$instances[$_profileID]))
593
+			{
594
+				unset(self::$instances[$_profileID]);
595
+			}
529 596
 		}
530 597
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
531 598
 		{
@@ -554,7 +621,10 @@  discard block
 block discarded – undo
554 621
 	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
555 622
 	{
556 623
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
557
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
624
+		if (is_null($account_id))
625
+		{
626
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
627
+		}
558 628
 		if (is_array($_ImapServerId))
559 629
 		{
560 630
 			// called via hook
@@ -593,7 +663,10 @@  discard block
 block discarded – undo
593 663
 	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
594 664
 	{
595 665
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
596
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
666
+		if (is_null($account_id))
667
+		{
668
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
669
+		}
597 670
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
598 671
 		// or treat it as not given. we try that path
599 672
 		if (is_null($_ImapServerId)||is_array($_ImapServerId))
@@ -667,10 +740,14 @@  discard block
 block discarded – undo
667 740
 
668 741
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
669 742
 
670
-		foreach($identities as $ik => $ident) {
743
+		foreach($identities as $ik => $ident)
744
+		{
671 745
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
672 746
 			$identity = Mail\Account::read_identity($ik);
673
-			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
747
+			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']]))
748
+			{
749
+				$userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
750
+			}
674 751
 		}
675 752
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
676 753
 		return $userEMailAdresses;
@@ -688,13 +765,20 @@  discard block
 block discarded – undo
688 765
 		foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
689 766
 		{
690 767
 			$acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
691
-			if (!$resolve_placeholders) $userEMailAdresses[$acc['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$acc['ident_id'],'ident_email'=>$acc['ident_email'],'ident_org'=>$acc['ident_org'],'ident_realname'=>$acc['ident_realname'],'ident_signature'=>$acc['ident_signature'],'ident_name'=>$acc['ident_name']);
768
+			if (!$resolve_placeholders)
769
+			{
770
+				$userEMailAdresses[$acc['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$acc['ident_id'],'ident_email'=>$acc['ident_email'],'ident_org'=>$acc['ident_org'],'ident_realname'=>$acc['ident_realname'],'ident_signature'=>$acc['ident_signature'],'ident_name'=>$acc['ident_name']);
771
+			}
692 772
 
693
-			foreach(Mail\Account::identities($acc) as $ik => $ident) {
773
+			foreach(Mail\Account::identities($acc) as $ik => $ident)
774
+			{
694 775
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
695 776
 				$identity = Mail\Account::read_identity($ik,$resolve_placeholders);
696 777
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
697
-				if (!isset($userEMailAdresses[$identity['ident_id']])) $userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$identity['ident_id'],'ident_email'=>$identity['ident_email'],'ident_org'=>$identity['ident_org'],'ident_realname'=>$identity['ident_realname'],'ident_signature'=>$identity['ident_signature'],'ident_name'=>$identity['ident_name']);
778
+				if (!isset($userEMailAdresses[$identity['ident_id']]))
779
+				{
780
+					$userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$identity['ident_id'],'ident_email'=>$identity['ident_email'],'ident_org'=>$identity['ident_org'],'ident_realname'=>$identity['ident_realname'],'ident_signature'=>$identity['ident_signature'],'ident_name'=>$identity['ident_name']);
781
+				}
698 782
 			}
699 783
 		}
700 784
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -714,12 +798,16 @@  discard block
 block discarded – undo
714 798
 			$account = Mail\Account::read($account);
715 799
 		}
716 800
 		$userEMailAdresses = array();
717
-		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) {
801
+		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident)
802
+		{
718 803
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
719 804
 			$identity = Mail\Account::read_identity($ik,true,null,$account);
720 805
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
721 806
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
722
-			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
807
+			if (empty($identity['ident_id']))
808
+			{
809
+				$identity['ident_id'] = $identity['acc_id'];
810
+			}
723 811
 			if (!isset($userEMailAdresses[$identity['ident_id']]))
724 812
 			{
725 813
 				$userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$identity['acc_id'],
@@ -762,15 +850,25 @@  discard block
 block discarded – undo
762 850
 		// account select box
763 851
 		$selectedID = $this->profileID;
764 852
 		$allAccountData = Mail\Account::search($only_current_user=true, false, null);
765
-		if ($allAccountData) {
853
+		if ($allAccountData)
854
+		{
766 855
 			$rememberFirst=$selectedFound=null;
767 856
 			foreach ($allAccountData as $tmpkey => $icServers)
768 857
 			{
769
-				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
770
-				if ($tmpkey == $selectedID) $selectedFound=true;
858
+				if (is_null($rememberFirst))
859
+				{
860
+					$rememberFirst = $tmpkey;
861
+				}
862
+				if ($tmpkey == $selectedID)
863
+				{
864
+					$selectedFound=true;
865
+				}
771 866
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
772 867
 				$host = $icServers->acc_imap_host;
773
-				if (empty($host)) continue;
868
+				if (empty($host))
869
+				{
870
+					continue;
871
+				}
774 872
 				$identities[$icServers->acc_id] = $icServers['ident_realname'].' '.$icServers['ident_org'].' <'.$icServers['ident_email'].'>';
775 873
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
776 874
 			}
@@ -830,7 +928,10 @@  discard block
 block discarded – undo
830 928
 	 */
831 929
 	function reopen($_foldername)
832 930
 	{
833
-		if (self::$debugTimes) $starttime = microtime (true);
931
+		if (self::$debugTimes)
932
+		{
933
+			$starttime = microtime (true);
934
+		}
834 935
 
835 936
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
836 937
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -840,12 +941,16 @@  discard block
 block discarded – undo
840 941
 		//{
841 942
 			//error_log( __METHOD__.' ('.__LINE__.') '." $_foldername ".function_backtrace());
842 943
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true));
843
-			if ($this->folderIsSelectable($_foldername)) {
944
+			if ($this->folderIsSelectable($_foldername))
945
+			{
844 946
 				$this->icServer->openMailbox($_foldername);
845 947
 			}
846 948
 			$folderOpened = $_foldername;
847 949
 		//}
848
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
950
+		if (self::$debugTimes)
951
+		{
952
+			self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
953
+		}
849 954
 	}
850 955
 
851 956
 
@@ -860,13 +965,22 @@  discard block
 block discarded – undo
860 965
 	{
861 966
 		//error_log( "-------------------------->open connection ".function_backtrace());
862 967
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
863
-		if (self::$debugTimes) $starttime = microtime (true);
968
+		if (self::$debugTimes)
969
+		{
970
+			$starttime = microtime (true);
971
+		}
864 972
 		$mailbox=null;
865 973
 		try
866 974
 		{
867
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
868
-			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
869
-/*
975
+			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox']))
976
+			{
977
+				$mailbox = $this->sessionData['mailbox'];
978
+			}
979
+			if (empty($mailbox))
980
+			{
981
+				$mailbox = $this->icServer->getCurrentMailbox();
982
+			}
983
+			/*
870 984
 			if (isset(Mail\Imap::$supports_keywords[$_icServerID]))
871 985
 			{
872 986
 				$this->icServer->openMailbox($mailbox);
@@ -891,7 +1005,10 @@  discard block
 block discarded – undo
891 1005
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage());
892 1006
 			throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage());
893 1007
 		}
894
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1008
+		if (self::$debugTimes)
1009
+		{
1010
+			self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1011
+		}
895 1012
 	}
896 1013
 
897 1014
 	/**
@@ -903,20 +1020,27 @@  discard block
 block discarded – undo
903 1020
 	function getQuotaRoot()
904 1021
 	{
905 1022
 		static $quota;
906
-		if (isset($quota)) return $quota;
1023
+		if (isset($quota))
1024
+		{
1025
+			return $quota;
1026
+		}
907 1027
 		$this->icServer->getCurrentMailbox();
908
-		if(!$this->icServer->hasCapability('QUOTA')) {
1028
+		if(!$this->icServer->hasCapability('QUOTA'))
1029
+		{
909 1030
 			$quota = false;
910 1031
 			return false;
911 1032
 		}
912 1033
 		$quota = $this->icServer->getStorageQuotaRoot('INBOX');
913 1034
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
914
-		if(is_array($quota)) {
1035
+		if(is_array($quota))
1036
+		{
915 1037
 			$quota = array(
916 1038
 				'usage'	=> $quota['USED'],
917 1039
 				'limit'	=> $quota['QMAX'],
918 1040
 			);
919
-		} else {
1041
+		}
1042
+		else
1043
+		{
920 1044
 			$quota = false;
921 1045
 		}
922 1046
 		return $quota;
@@ -932,7 +1056,11 @@  discard block
 block discarded – undo
932 1056
 	static function getTimeOut($_use='IMAP')
933 1057
 	{
934 1058
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
935
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
1059
+		if (empty($timeout))
1060
+		{
1061
+			$timeout = ($_use=='SIEVE'?10:20);
1062
+		}
1063
+		// this is the default value
936 1064
 		return $timeout;
937 1065
 	}
938 1066
 
@@ -950,9 +1078,13 @@  discard block
 block discarded – undo
950 1078
 		$foldersNameSpace = array();
951 1079
 		$delimiter = $this->getHierarchyDelimiter();
952 1080
 		// TODO: cache by $this->icServer->ImapServerId
953
-		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
1081
+		if (is_null($nameSpace))
1082
+		{
1083
+			$nameSpace = $this->icServer->getNameSpaceArray();
1084
+		}
954 1085
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
955
-		if (is_array($nameSpace)) {
1086
+		if (is_array($nameSpace))
1087
+		{
956 1088
 			foreach($nameSpace as $type => $singleNameSpaceArray)
957 1089
 			{
958 1090
 				foreach ($singleNameSpaceArray as $singleNameSpace)
@@ -969,7 +1101,9 @@  discard block
 block discarded – undo
969 1101
 						$_foldersNameSpace['prefix_present'] = 'forced';
970 1102
 						// uw-imap server with mailbox prefix or dovecot maybe
971 1103
 						$_foldersNameSpace['prefix'] = 'mail';
972
-					} else {
1104
+					}
1105
+					else
1106
+					{
973 1107
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
974 1108
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
975 1109
 					}
@@ -996,7 +1130,10 @@  discard block
 block discarded – undo
996 1130
 		foreach($nameSpace as &$singleNameSpace)
997 1131
 		{
998 1132
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
999
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1133
+			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix'])
1134
+			{
1135
+				return $singleNameSpace['prefix'];
1136
+			}
1000 1137
 		}
1001 1138
 		return "";
1002 1139
 	}
@@ -1010,8 +1147,14 @@  discard block
 block discarded – undo
1010 1147
 	function getHierarchyDelimiter($_useCache=true)
1011 1148
 	{
1012 1149
 		static $HierarchyDelimiter = null;
1013
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1014
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1150
+		if (is_null($HierarchyDelimiter))
1151
+		{
1152
+			$HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1153
+		}
1154
+		if ($_useCache===false)
1155
+		{
1156
+			unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1157
+		}
1015 1158
 		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1016 1159
 		{
1017 1160
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
@@ -1040,14 +1183,19 @@  discard block
 block discarded – undo
1040 1183
 	{
1041 1184
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1042 1185
 		static $_specialUseFolders = null;
1043
-		if (is_null($_specialUseFolders)||empty($_specialUseFolders)) $_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1186
+		if (is_null($_specialUseFolders)||empty($_specialUseFolders))
1187
+		{
1188
+			$_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1189
+		}
1044 1190
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1045 1191
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1046 1192
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
1047 1193
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_template));
1048 1194
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1049 1195
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1050
-			return $_specialUseFolders[$this->icServer->ImapServerId];
1196
+		{
1197
+					return $_specialUseFolders[$this->icServer->ImapServerId];
1198
+		}
1051 1199
 		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1052 1200
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1053 1201
 			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
@@ -1075,7 +1223,8 @@  discard block
 block discarded – undo
1075 1223
 	function folderIsSelectable($folderToSelect)
1076 1224
 	{
1077 1225
 		$retval = true;
1078
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1226
+		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true)))
1227
+		{
1079 1228
 			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1080 1229
 			{
1081 1230
 				$retval = false;
@@ -1128,18 +1277,27 @@  discard block
 block discarded – undo
1128 1277
 	 */
1129 1278
 	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1130 1279
 	{
1131
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1132
-		if (!is_string($_folderName) || empty($_folderName)) // something is wrong. Do not proceed
1280
+		if (self::$debug)
1281
+		{
1282
+			error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1283
+		}
1284
+		if (!is_string($_folderName) || empty($_folderName))
1285
+		{
1286
+			// something is wrong. Do not proceed
1133 1287
 		{
1134 1288
 			return false;
1135 1289
 		}
1290
+		}
1136 1291
 		static $folderInfoCache = null; // reduce traffic on single request
1137 1292
 		static $folderBasicInfo = null;
1138 1293
 		if (isset($folderBasicInfo[$this->profileID]))
1139 1294
 		{
1140 1295
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1141 1296
 		}
1142
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1297
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly)
1298
+		{
1299
+			return $folderInfoCache[$_folderName];
1300
+		}
1143 1301
 		$retValue = array();
1144 1302
 		$retValue['subscribed'] = false;
1145 1303
 /*
@@ -1157,7 +1315,10 @@  discard block
 block discarded – undo
1157 1315
 			if (is_array($ret))
1158 1316
 			{
1159 1317
 				$retkeys = array_keys($ret);
1160
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1318
+				if ($retkeys[0]==$_folderName)
1319
+				{
1320
+					$folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1321
+				}
1161 1322
 			}
1162 1323
 			else
1163 1324
 			{
@@ -1166,7 +1327,8 @@  discard block
 block discarded – undo
1166 1327
 		}
1167 1328
 		$folderInfo = $folderInfoCache[$_folderName];
1168 1329
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1169
-		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) {
1330
+		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo))
1331
+		{
1170 1332
 			try
1171 1333
 			{
1172 1334
 				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
@@ -1196,7 +1358,8 @@  discard block
 block discarded – undo
1196 1358
 		$retValue['shortName']		= array_pop($shortNameParts);
1197 1359
 		$retValue['displayName']	= $_folderName;
1198 1360
 		$retValue['shortDisplayName']	= $retValue['shortName'];
1199
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1361
+		if(strtoupper($retValue['shortName']) == 'INBOX')
1362
+		{
1200 1363
 			$retValue['displayName']	= lang('INBOX');
1201 1364
 			$retValue['shortDisplayName']	= lang('INBOX');
1202 1365
 		}
@@ -1205,7 +1368,10 @@  discard block
 block discarded – undo
1205 1368
 		{
1206 1369
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1207 1370
 		}
1208
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1371
+		if ($folderInfo)
1372
+		{
1373
+			$folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1374
+		}
1209 1375
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1210 1376
 		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1211 1377
 		{
@@ -1217,24 +1383,34 @@  discard block
 block discarded – undo
1217 1383
 		static $subscribedFolders = null;
1218 1384
 		static $nameSpace = null;
1219 1385
 		static $prefix = null;
1220
-		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1386
+		if (is_null($nameSpace) || empty($nameSpace[$this->profileID]))
1387
+		{
1388
+			$nameSpace[$this->profileID] = $this->_getNameSpaces();
1389
+		}
1221 1390
 		if (!empty($nameSpace[$this->profileID]))
1222 1391
 		{
1223 1392
 			$nsNoPersonal=array();
1224 1393
 			foreach($nameSpace[$this->profileID] as &$ns)
1225 1394
 			{
1226
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1395
+				if ($ns['type']!='personal')
1396
+				{
1397
+					$nsNoPersonal[]=$ns;
1398
+				}
1227 1399
 			}
1228 1400
 			$nameSpace[$this->profileID]=$nsNoPersonal;
1229 1401
 		}
1230
-		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1402
+		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName]))
1403
+		{
1404
+			$prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1405
+		}
1231 1406
 
1232 1407
 		if ($fetchSubscribedInfo && is_null($subscribedFolders) || empty($subscribedFolders[$this->profileID]))
1233 1408
 		{
1234 1409
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1235 1410
 		}
1236 1411
 
1237
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1412
+		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID]))
1413
+		{
1238 1414
 			$retValue['subscribed'] = true;
1239 1415
 		}
1240 1416
 
@@ -1253,8 +1429,7 @@  discard block
 block discarded – undo
1253 1429
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1254 1430
 				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1255 1431
 				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1256
-			)
1257
-			{
1432
+			) {
1258 1433
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1259 1434
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1260 1435
 				try
@@ -1264,13 +1439,19 @@  discard block
 block discarded – undo
1264 1439
 				}
1265 1440
 				catch (\Exception $ee)
1266 1441
 				{
1267
-					if (self::$debug) error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1442
+					if (self::$debug)
1443
+					{
1444
+						error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1445
+					}
1268 1446
 				}
1269 1447
 			}
1270 1448
 		}
1271 1449
 		catch (\Exception $e)
1272 1450
 		{
1273
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1451
+			if (self::$debug)
1452
+			{
1453
+				error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1454
+			}
1274 1455
 		}
1275 1456
 
1276 1457
 		return $retValue;
@@ -1295,8 +1476,14 @@  discard block
 block discarded – undo
1295 1476
 	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1296 1477
 	{
1297 1478
 		//self::$debug=true;
1298
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1299
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1479
+		if (self::$debug)
1480
+		{
1481
+			error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1482
+		}
1483
+		if (self::$debug)
1484
+		{
1485
+			error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1486
+		}
1300 1487
 		$reverse = (bool)$_reverse;
1301 1488
 		// get the list of messages to fetch
1302 1489
 		$this->reopen($_folderName);
@@ -1317,21 +1504,34 @@  discard block
 block discarded – undo
1317 1504
 				//$_filter['range'] ="$start:$end";
1318 1505
 				//$_filter['range'] ="$_startMessage:*";
1319 1506
 			}
1320
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1321
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1507
+			if (self::$debug)
1508
+			{
1509
+				error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1510
+			}
1511
+			if (self::$debug||self::$debugTimes)
1512
+			{
1513
+				$starttime = microtime (true);
1514
+			}
1322 1515
 			//see this example below for a 12 week datefilter (since)
1323 1516
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1324 1517
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1325 1518
 			$sortResult = $_sortResult['match']->ids;
1326 1519
 			//$modseq = $_sortResult['modseq'];
1327 1520
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1328
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1521
+			if (self::$debug||self::$debugTimes)
1522
+			{
1523
+				self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1524
+			}
1329 1525
 
1330
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1526
+			if (self::$debug)
1527
+			{
1528
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1529
+			}
1331 1530
 			#$this->icServer->setDebug(false);
1332 1531
 			#print "</pre>";
1333 1532
 			// nothing found
1334
-			if(!is_array($sortResult) || empty($sortResult)) {
1533
+			if(!is_array($sortResult) || empty($sortResult))
1534
+			{
1335 1535
 				$retValue = array();
1336 1536
 				$retValue['info']['total']	= 0;
1337 1537
 				$retValue['info']['first']	= 0;
@@ -1343,7 +1543,8 @@  discard block
 block discarded – undo
1343 1543
 			#_debug_array($sortResult);
1344 1544
 			#_debug_array(array_slice($sortResult, -5, -2));
1345 1545
 			//error_log("REVERSE: $reverse");
1346
-			if($reverse === true) {
1546
+			if($reverse === true)
1547
+			{
1347 1548
 				if  ($_startMessage<=$total)
1348 1549
 				{
1349 1550
 					$startMessage = $_startMessage-1;
@@ -1355,7 +1556,10 @@  discard block
 block discarded – undo
1355 1556
 					{
1356 1557
 						$numberOfMessages = $total%$_numberOfMessages;
1357 1558
 						//$numberOfMessages = abs($_startMessage-$total-1);
1358
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1559
+						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages)
1560
+						{
1561
+							$_numberOfMessages = $numberOfMessages;
1562
+						}
1359 1563
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1360 1564
 					}
1361 1565
 					$startMessage=($total-$_numberOfMessages)-1;
@@ -1369,19 +1573,36 @@  discard block
 block discarded – undo
1369 1573
 					//$retValue['info']['first'] = $startMessage;
1370 1574
 					//$retValue['info']['last'] = $total;
1371 1575
 				}
1372
-				if($startMessage > 0) {
1373
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1576
+				if($startMessage > 0)
1577
+				{
1578
+					if (self::$debug)
1579
+					{
1580
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1581
+					}
1374 1582
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1375
-				} else {
1376
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1583
+				}
1584
+				else
1585
+				{
1586
+					if (self::$debug)
1587
+					{
1588
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1589
+					}
1377 1590
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1378 1591
 				}
1379 1592
 				$sortResult = array_reverse($sortResult);
1380
-			} else {
1381
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1593
+			}
1594
+			else
1595
+			{
1596
+				if (self::$debug)
1597
+				{
1598
+					error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1599
+				}
1382 1600
 				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1383 1601
 			}
1384
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1602
+			if (self::$debug)
1603
+			{
1604
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1605
+			}
1385 1606
 		}
1386 1607
 		else
1387 1608
 		{
@@ -1390,7 +1611,10 @@  discard block
 block discarded – undo
1390 1611
 
1391 1612
 
1392 1613
 		// fetch the data for the selected messages
1393
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1614
+		if (self::$debug||self::$debugTimes)
1615
+		{
1616
+			$starttime = microtime(true);
1617
+		}
1394 1618
 		try
1395 1619
 		{
1396 1620
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1414,7 +1638,10 @@  discard block
 block discarded – undo
1414 1638
 			$fquery->flags();
1415 1639
 			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1416 1640
 			// if $_fetchPreviews is activated fetch part of the messages too
1417
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1641
+			if ($_fetchPreviews)
1642
+			{
1643
+				$fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1644
+			}
1418 1645
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1419 1646
 				'ids' => $uidsToFetch,
1420 1647
 			));
@@ -1437,14 +1664,20 @@  discard block
 block discarded – undo
1437 1664
 
1438 1665
 		$cnt = 0;
1439 1666
 
1440
-		foreach((array)$sortResult as $uid) {
1667
+		foreach((array)$sortResult as $uid)
1668
+		{
1441 1669
 			$sortOrder[$uid] = $cnt++;
1442 1670
 		}
1443 1671
 
1444 1672
 		$count = 0;
1445
-		if (is_object($headersNew)) {
1446
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1447
-			foreach($headersNew->ids() as $id) {
1673
+		if (is_object($headersNew))
1674
+		{
1675
+			if (self::$debug||self::$debugTimes)
1676
+			{
1677
+				$starttime = microtime(true);
1678
+			}
1679
+			foreach($headersNew->ids() as $id)
1680
+			{
1448 1681
 				$_headerObject = $headersNew->get($id);
1449 1682
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1450 1683
 				$headerObject = array();
@@ -1456,8 +1689,12 @@  discard block
 block discarded – undo
1456 1689
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1457 1690
 				$headerForPrio = array_change_key_case($_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1458 1691
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1459
-				if (empty($headerForPrio)) $headerForPrio = array_change_key_case($_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1460
-				if (self::$debug) {
1692
+				if (empty($headerForPrio))
1693
+				{
1694
+					$headerForPrio = array_change_key_case($_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1695
+				}
1696
+				if (self::$debug)
1697
+				{
1461 1698
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject).'UID:'.$_headerObject->getUid().' Size:'.$_headerObject->getSize().' Date:'.$_headerObject->getImapDate().'/'.DateTime::to($_headerObject->getImapDate(),'Y-m-d H:i:s'));
1462 1699
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1463 1700
 				}
@@ -1468,11 +1705,16 @@  discard block
 block discarded – undo
1468 1705
 					$total--;
1469 1706
 					continue;
1470 1707
 				}
1471
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1708
+				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) )
1709
+				{
1472 1710
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1473
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1711
+				}
1712
+				else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) )
1713
+				{
1474 1714
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1475
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1715
+				}
1716
+				else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) )
1717
+				{
1476 1718
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1477 1719
 				} /*else $sent_not = "";*/
1478 1720
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
@@ -1503,7 +1745,11 @@  discard block
 block discarded – undo
1503 1745
 						$rfcAddr = self::parseAddressList($ad); // does some fixing of known problems too
1504 1746
 						foreach ($rfcAddr as $_rfcAddr)
1505 1747
 						{
1506
-							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1748
+							if (!$_rfcAddr->valid)
1749
+							{
1750
+								continue;
1751
+							}
1752
+							// skip. not a valid address
1507 1753
 							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1508 1754
 						}
1509 1755
 					}
@@ -1530,7 +1776,8 @@  discard block
 block discarded – undo
1530 1776
 												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1531 1777
 											)), $charset, 'utf-8');
1532 1778
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1533
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1779
+						}
1780
+						elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1534 1781
 						{
1535 1782
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1536 1783
 						}
@@ -1546,7 +1793,10 @@  discard block
 block discarded – undo
1546 1793
 				$messageMimeType='';
1547 1794
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1548 1795
 				{
1549
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1796
+					if ($mime_id==0 || $messageMimeType==='')
1797
+					{
1798
+						$messageMimeType = $mime_type;
1799
+					}
1550 1800
 					$part = $mailStructureObject->getPart($mime_id);
1551 1801
 					$partdisposition = $part->getDisposition();
1552 1802
 					$partPrimaryType = $part->getPrimaryType();
@@ -1556,7 +1806,8 @@  discard block
 block discarded – undo
1556 1806
 					// bodypreview could be found (multipart/....)
1557 1807
 					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1558 1808
 						((intval($mime_id) === 1) || !$mime_id) &&
1559
-						($partdisposition !== 'attachment')) {
1809
+						($partdisposition !== 'attachment'))
1810
+					{
1560 1811
 							$_structure=$part;
1561 1812
 							$this->fetchPartContents($uid, $_structure, false,true);
1562 1813
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
@@ -1578,10 +1829,19 @@  discard block
 block discarded – undo
1578 1829
 					if ($mime_type=='message/rfc822')
1579 1830
 					{
1580 1831
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1581
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1832
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
1833
+						{
1834
+if ($sub_id != $mime_id)
1835
+						{
1836
+							$skipParts[$sub_id] = $sub_type;
1837
+						}
1838
+						}
1582 1839
 					}
1583 1840
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1584
-					if (array_key_exists($mime_id,$skipParts)) continue;
1841
+					if (array_key_exists($mime_id,$skipParts))
1842
+					{
1843
+						continue;
1844
+					}
1585 1845
 					if ($partdisposition=='attachment' ||
1586 1846
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1587 1847
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
@@ -1592,7 +1852,10 @@  discard block
 block discarded – undo
1592 1852
 						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1593 1853
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1594 1854
 						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1595
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1855
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))
1856
+						{
1857
+							$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1858
+						}
1596 1859
 						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1597 1860
 							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1598 1861
 						{
@@ -1606,18 +1869,27 @@  discard block
 block discarded – undo
1606 1869
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (plain):'.array2string($mailStructureObject->findBody('plain')));
1607 1870
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (html):'.array2string($mailStructureObject->findBody('html')));
1608 1871
 				//if($count == 0) error_log(__METHOD__.array2string($headerObject));
1609
-				if (empty($headerObject['UID'])) continue;
1872
+				if (empty($headerObject['UID']))
1873
+				{
1874
+					continue;
1875
+				}
1610 1876
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1611 1877
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1612
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1878
+				if(substr($headerObject['DATE'],-2) === 'UT')
1879
+				{
1613 1880
 					$headerObject['DATE'] .= 'C';
1614 1881
 				}
1615
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1882
+				if(substr($headerObject['INTERNALDATE'],-2) === 'UT')
1883
+				{
1616 1884
 					$headerObject['INTERNALDATE'] .= 'C';
1617 1885
 				}
1618 1886
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1619 1887
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1620
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1888
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS']))
1889
+				{
1890
+					foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;
1891
+				}
1892
+				}
1621 1893
 				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1622 1894
 				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1623 1895
 				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
@@ -1628,22 +1900,31 @@  discard block
 block discarded – undo
1628 1900
 				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1629 1901
 				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1630 1902
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1631
-				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1632
-				if (is_array($headerObject['FLAGS'])) {
1903
+				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO']))
1904
+				{
1905
+					$retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1906
+				}
1907
+				if (is_array($headerObject['FLAGS']))
1908
+				{
1633 1909
 					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1634 1910
 				}
1635 1911
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1636
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1912
+				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0])
1913
+				{
1637 1914
 					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1638 1915
 				}
1639
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1916
+				if(is_array($headerObject['TO']) && $headerObject['TO'][0])
1917
+				{
1640 1918
 					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1641 1919
 					if (count($headerObject['TO'])>1)
1642 1920
 					{
1643 1921
 						$ki=0;
1644 1922
 						foreach($headerObject['TO'] as $k => $add)
1645 1923
 						{
1646
-							if ($k==0) continue;
1924
+							if ($k==0)
1925
+							{
1926
+								continue;
1927
+							}
1647 1928
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1648 1929
 							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1649 1930
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
@@ -1651,7 +1932,8 @@  discard block
 block discarded – undo
1651 1932
 						}
1652 1933
 					}
1653 1934
 				}
1654
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
1935
+				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0)
1936
+				{
1655 1937
 					$ki=0;
1656 1938
 					foreach($headerObject['CC'] as $k => $add)
1657 1939
 					{
@@ -1665,27 +1947,41 @@  discard block
 block discarded – undo
1665 1947
 
1666 1948
 				$count++;
1667 1949
 			}
1668
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1950
+			if (self::$debug||self::$debugTimes)
1951
+			{
1952
+				self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1953
+			}
1669 1954
 			//self::$debug=false;
1670 1955
 			// sort the messages to the requested displayorder
1671
-			if(is_array($retValue['header'])) {
1956
+			if(is_array($retValue['header']))
1957
+			{
1672 1958
 				$countMessages = $total;
1673
-				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1959
+				if (isset($_filter['range']))
1960
+				{
1961
+					$countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1962
+				}
1674 1963
 				ksort($retValue['header']);
1675 1964
 				$retValue['info']['total']	= $total;
1676 1965
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1677 1966
 				$retValue['info']['first']	= $_startMessage;
1678 1967
 				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1679 1968
 				return $retValue;
1680
-			} else {
1969
+			}
1970
+			else
1971
+			{
1681 1972
 				$retValue = array();
1682 1973
 				$retValue['info']['total']	= 0;
1683 1974
 				$retValue['info']['first']	= 0;
1684 1975
 				$retValue['info']['last']	= 0;
1685 1976
 				return $retValue;
1686 1977
 			}
1687
-		} else {
1688
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
1978
+		}
1979
+		else
1980
+		{
1981
+			if ($headersNew == null && empty($_thisUIDOnly))
1982
+			{
1983
+				error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
1984
+			}
1689 1985
 			$retValue = array();
1690 1986
 			$retValue['info']['total']  = 0;
1691 1987
 			$retValue['info']['first']  = 0;
@@ -1702,7 +1998,10 @@  discard block
 block discarded – undo
1702 1998
 	 */
1703 1999
 	static function prepareFlagsArray($headerObject)
1704 2000
 	{
1705
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2001
+		if (is_array($headerObject['FLAGS']))
2002
+		{
2003
+			$headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2004
+		}
1706 2005
 		$retValue = array();
1707 2006
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1708 2007
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
@@ -1753,24 +2052,43 @@  discard block
 block discarded – undo
1753 2052
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1754 2053
 		$try2useCache = true;
1755 2054
 		static $eMailListContainsDeletedMessages = null;
1756
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2055
+		if (is_null($eMailListContainsDeletedMessages))
2056
+		{
2057
+			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2058
+		}
1757 2059
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1758 2060
 		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1759 2061
 		{
1760
-			if (self::$debugTimes) $starttime = microtime(true);
1761
-			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2062
+			if (self::$debugTimes)
2063
+			{
2064
+				$starttime = microtime(true);
2065
+			}
2066
+			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName]))
2067
+			{
2068
+				$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2069
+			}
1762 2070
 			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five=true,false);
1763
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2071
+			if (self::$debug)
2072
+			{
2073
+				error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2074
+			}
1764 2075
 			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1765 2076
 			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1766
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');			//error_log(__METHOD__.' ('.__LINE__.') '.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
2077
+			if (self::$debugTimes)
2078
+			{
2079
+				self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');
2080
+			}
2081
+			//error_log(__METHOD__.' ('.__LINE__.') '.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
1767 2082
 		}
1768 2083
 		$try2useCache = false;
1769 2084
 		//self::$supportsORinQuery[$this->profileID]=true;
1770 2085
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1771 2086
 		{
1772 2087
 			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1773
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
2088
+			if (!isset(self::$supportsORinQuery[$this->profileID]))
2089
+			{
2090
+				self::$supportsORinQuery[$this->profileID]=true;
2091
+			}
1774 2092
 		}
1775 2093
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1776 2094
 		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
@@ -1781,15 +2099,26 @@  discard block
 block discarded – undo
1781 2099
 		}
1782 2100
 		//_debug_array($filter);
1783 2101
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1784
-		if($this->icServer->hasCapability('SORT')) {
2102
+		if($this->icServer->hasCapability('SORT'))
2103
+		{
1785 2104
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1786 2105
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1787 2106
 			// there is no messing with the dates)
1788 2107
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1789
-			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2108
+			if (self::$debug)
2109
+			{
2110
+				error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2111
+			}
1790 2112
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1791
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1792
-			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2113
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder))
2114
+			{
2115
+				$_reverse=false;
2116
+			}
2117
+			// as we reversed the result already
2118
+			if (self::$debug)
2119
+			{
2120
+				error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2121
+			}
1793 2122
 			try
1794 2123
 			{
1795 2124
 				$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1801,7 +2130,10 @@  discard block
 block discarded – undo
1801 2130
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1802 2131
 				$resultByUid = false;
1803 2132
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1804
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2133
+				if ($_reverse)
2134
+				{
2135
+					array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2136
+				}
1805 2137
 				try
1806 2138
 				{
1807 2139
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1813,9 +2145,17 @@  discard block
 block discarded – undo
1813 2145
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1814 2146
 				}
1815 2147
 			}
1816
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1817
-		} else {
1818
-			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
2148
+			if (self::$debug)
2149
+			{
2150
+				error_log(__METHOD__.print_r($sortResult,true));
2151
+			}
2152
+		}
2153
+		else
2154
+		{
2155
+			if (self::$debug)
2156
+			{
2157
+				error_log(__METHOD__." Mailserver has NO SORT Capability");
2158
+			}
1819 2159
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1820 2160
 			//if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1821 2161
 			try
@@ -1829,7 +2169,10 @@  discard block
 block discarded – undo
1829 2169
 				// possible error OR Query. But Horde gives no detailed Info :-(
1830 2170
 				self::$supportsORinQuery[$this->profileID]=false;
1831 2171
 				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1832
-				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2172
+				if (self::$debug)
2173
+				{
2174
+					error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2175
+				}
1833 2176
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1834 2177
 				try
1835 2178
 				{
@@ -1840,11 +2183,15 @@  discard block
 block discarded – undo
1840 2183
 				{
1841 2184
 				}
1842 2185
 			}
1843
-			if(is_array($sortResult['match'])) {
2186
+			if(is_array($sortResult['match']))
2187
+			{
1844 2188
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1845 2189
 					sort($sortResult['match'], SORT_NUMERIC);
1846 2190
 			}
1847
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2191
+			if (self::$debug)
2192
+			{
2193
+				error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2194
+			}
1848 2195
 		}
1849 2196
 		if ($setSession)
1850 2197
 		{
@@ -1873,7 +2220,8 @@  discard block
 block discarded – undo
1873 2220
 		$_reverse=false;
1874 2221
 		if (is_numeric($_sort))
1875 2222
 		{
1876
-			switch($_sort) {
2223
+			switch($_sort)
2224
+			{
1877 2225
 				case 2:
1878 2226
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1879 2227
 					break;
@@ -1895,7 +2243,8 @@  discard block
 block discarded – undo
1895 2243
 		}
1896 2244
 		else
1897 2245
 		{
1898
-			switch(strtoupper($_sort)) {
2246
+			switch(strtoupper($_sort))
2247
+			{
1899 2248
 				case 'FROMADDRESS':
1900 2249
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1901 2250
 					break;
@@ -1921,7 +2270,10 @@  discard block
 block discarded – undo
1921 2270
 					break;
1922 2271
 			}
1923 2272
 		}
1924
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2273
+		if ($_reverse)
2274
+		{
2275
+			array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2276
+		}
1925 2277
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1926 2278
 		return $retValue;
1927 2279
 	}
@@ -1940,7 +2292,10 @@  discard block
 block discarded – undo
1940 2292
 		$imapFilter->charset('UTF-8');
1941 2293
 
1942 2294
 		//_debug_array($_criterias);
1943
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2295
+		if (self::$debug)
2296
+		{
2297
+			error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2298
+		}
1944 2299
 		if((!is_array($_criterias) || $_criterias['status']=='any') &&
1945 2300
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
1946 2301
 			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
@@ -1955,11 +2310,13 @@  discard block
 block discarded – undo
1955 2310
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
1956 2311
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
1957 2312
 		$statusQueryValid = false;
1958
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2313
+		foreach((array)$_criterias['status'] as $k => $criteria)
2314
+		{
1959 2315
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
1960 2316
 			$imapStatusFilter->charset('UTF-8');
1961 2317
 			$criteria = strtoupper($criteria);
1962
-			switch ($criteria) {
2318
+			switch ($criteria)
2319
+			{
1963 2320
 				case 'ANSWERED':
1964 2321
 				case 'DELETED':
1965 2322
 				case 'FLAGGED':
@@ -2042,9 +2399,11 @@  discard block
 block discarded – undo
2042 2399
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2043 2400
 		$imapSearchFilter->charset('UTF-8');
2044 2401
 
2045
-		if(!empty($_criterias['string'])) {
2402
+		if(!empty($_criterias['string']))
2403
+		{
2046 2404
 			$criteria = strtoupper($_criterias['type']);
2047
-			switch ($criteria) {
2405
+			switch ($criteria)
2406
+			{
2048 2407
 				case 'BYDATE':
2049 2408
 				case 'QUICK':
2050 2409
 				case 'QUICKWITHCC':
@@ -2052,9 +2411,12 @@  discard block
 block discarded – undo
2052 2411
 					//$imapSearchFilter->charset('UTF-8');
2053 2412
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2054 2413
 					$imapFilter2->charset('UTF-8');
2055
-					if($this->isSentFolder($_folder)) {
2414
+					if($this->isSentFolder($_folder))
2415
+					{
2056 2416
 						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2057
-					} else {
2417
+					}
2418
+					else
2419
+					{
2058 2420
 						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2059 2421
 					}
2060 2422
 					if ($_supportsOrInQuery)
@@ -2085,7 +2447,10 @@  discard block
 block discarded – undo
2085 2447
 											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2086 2448
 											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2087 2449
 						$numberinBytes=(float)$_criterias['string'];
2088
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2450
+						if (isset($multipleBy[$unit]))
2451
+						{
2452
+							$numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2453
+						}
2089 2454
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2090 2455
 						$_criterias['string']=$numberinBytes;
2091 2456
 					}
@@ -2122,8 +2487,14 @@  discard block
 block discarded – undo
2122 2487
 					break;
2123 2488
 			}
2124 2489
 		}
2125
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2126
-		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2490
+		if ($statusQueryValid && !$queryValid)
2491
+		{
2492
+			$queryValid=true;
2493
+		}
2494
+		if ($queryValid)
2495
+		{
2496
+			$imapFilter->andSearch($imapSearchFilter);
2497
+		}
2127 2498
 
2128 2499
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
2129 2500
 		{
@@ -2138,7 +2509,8 @@  discard block
 block discarded – undo
2138 2509
 				unset($_criterias['before']);
2139 2510
 				$criteria=$_criterias['range']='ON';
2140 2511
 			}
2141
-			switch ($criteria) {
2512
+			switch ($criteria)
2513
+			{
2142 2514
 				case 'BETWEEN':
2143 2515
 					//try to be smart about missing
2144 2516
 					//enddate
@@ -2174,8 +2546,14 @@  discard block
 block discarded – undo
2174 2546
 					$rangeValid = true;
2175 2547
 					break;
2176 2548
 			}
2177
-			if ($rangeValid && !$queryValid) $queryValid=true;
2178
-			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2549
+			if ($rangeValid && !$queryValid)
2550
+			{
2551
+				$queryValid=true;
2552
+			}
2553
+			if ($rangeValid)
2554
+			{
2555
+				$imapFilter->andSearch($imapRangeFilter);
2556
+			}
2179 2557
 		}
2180 2558
 		if (self::$debug)
2181 2559
 		{
@@ -2183,10 +2561,13 @@  discard block
 block discarded – undo
2183 2561
 			$query_str = $imapFilter->build();
2184 2562
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2185 2563
 		}
2186
-		if($queryValid==false) {
2564
+		if($queryValid==false)
2565
+		{
2187 2566
 			$imapFilter->flag('DELETED', $set=false);
2188 2567
 			return $imapFilter;
2189
-		} else {
2568
+		}
2569
+		else
2570
+		{
2190 2571
 			return $imapFilter;
2191 2572
 		}
2192 2573
 	}
@@ -2243,7 +2624,10 @@  discard block
 block discarded – undo
2243 2624
 					}
2244 2625
 					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2245 2626
 				}
2246
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2627
+				if (!empty($stringA))
2628
+				{
2629
+					$_string = implode(',',$stringA);
2630
+				}
2247 2631
 			}
2248 2632
 			if ($_tryIDNConversion==='FORCE')
2249 2633
 			{
@@ -2268,7 +2652,10 @@  discard block
 block discarded – undo
2268 2652
 		{
2269 2653
 			return 'No Subject';
2270 2654
 		}
2271
-		if ($decode) $_string = self::decode_header($_string);
2655
+		if ($decode)
2656
+		{
2657
+			$_string = self::decode_header($_string);
2658
+		}
2272 2659
 		// make sure its utf-8
2273 2660
 		$test = @json_encode($_string);
2274 2661
 		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
@@ -2306,7 +2693,8 @@  discard block
 block discarded – undo
2306 2693
 	 * @param string _parent the parent foldername
2307 2694
 	 * @return ISO-8859-1 / UTF7-IMAP encoded string
2308 2695
 	 */
2309
-	function _encodeFolderName($_folderName) {
2696
+	function _encodeFolderName($_folderName)
2697
+	{
2310 2698
 		return Translation::convert($_folderName, self::$displayCharset, 'ISO-8859-1');
2311 2699
 		#return Translation::convert($_folderName, self::$displayCharset, 'UTF7-IMAP');
2312 2700
 	}
@@ -2322,21 +2710,36 @@  discard block
 block discarded – undo
2322 2710
 	 */
2323 2711
 	function createFolder($_parent, $_folderName, &$_error)
2324 2712
 	{
2325
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2713
+		if (self::$debug)
2714
+		{
2715
+			error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2716
+		}
2326 2717
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2327 2718
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2328 2719
 
2329
-		if(empty($parent)) {
2720
+		if(empty($parent))
2721
+		{
2330 2722
 			$newFolderName = $folderName;
2331
-		} else {
2723
+		}
2724
+		else
2725
+		{
2332 2726
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2333 2727
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2334 2728
 		}
2335
-		if (empty($newFolderName)) return false;
2336
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2729
+		if (empty($newFolderName))
2730
+		{
2731
+			return false;
2732
+		}
2733
+		if (self::$debug)
2734
+		{
2735
+			error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2736
+		}
2337 2737
 		if ($this->folderExists($newFolderName,true))
2338 2738
 		{
2339
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2739
+			if (self::$debug)
2740
+			{
2741
+				error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2742
+			}
2340 2743
 			return $newFolderName;
2341 2744
 		}
2342 2745
 		try
@@ -2384,13 +2787,19 @@  discard block
 block discarded – undo
2384 2787
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2385 2788
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2386 2789
 
2387
-		if(empty($parent)) {
2790
+		if(empty($parent))
2791
+		{
2388 2792
 			$newFolderName = $folderName;
2389
-		} else {
2793
+		}
2794
+		else
2795
+		{
2390 2796
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2391 2797
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2392 2798
 		}
2393
-		if (self::$debug) error_log("create folder: $newFolderName");
2799
+		if (self::$debug)
2800
+		{
2801
+			error_log("create folder: $newFolderName");
2802
+		}
2394 2803
 		try
2395 2804
 		{
2396 2805
 			$this->icServer->renameMailbox($oldFolderName, $newFolderName);
@@ -2464,8 +2873,14 @@  discard block
 block discarded – undo
2464 2873
 	 */
2465 2874
 	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2466 2875
 	{
2467
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2468
-		if (self::$debugTimes) $starttime = microtime (true);
2876
+		if (self::$debug)
2877
+		{
2878
+			error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2879
+		}
2880
+		if (self::$debugTimes)
2881
+		{
2882
+			$starttime = microtime (true);
2883
+		}
2469 2884
 		static $folders2return;
2470 2885
 		//$_subscribedOnly=false;
2471 2886
 		// always use static on single request if info is available;
@@ -2473,23 +2888,35 @@  discard block
 block discarded – undo
2473 2888
 		// set $_useCacheIfPossible to false !
2474 2889
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2475 2890
 		{
2476
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2891
+			if (self::$debugTimes)
2892
+			{
2893
+				self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2894
+			}
2477 2895
 			return $folders2return[$this->icServer->ImapServerId];
2478 2896
 		}
2479 2897
 
2480 2898
 		if ($_subscribedOnly && $_getCounters===false)
2481 2899
 		{
2482
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2900
+			if (is_null($folders2return))
2901
+			{
2902
+				$folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2903
+			}
2483 2904
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2484 2905
 			{
2485 2906
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2486
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2907
+				if (self::$debugTimes)
2908
+				{
2909
+					self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2910
+				}
2487 2911
 				return $folders2return[$this->icServer->ImapServerId];
2488 2912
 			}
2489 2913
 		}
2490 2914
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2491 2915
 		static $folderBasicInfo;
2492
-		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId])) $folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2916
+		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId]))
2917
+		{
2918
+			$folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2919
+		}
2493 2920
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2494 2921
 
2495 2922
 		$delimiter = $this->getHierarchyDelimiter();
@@ -2502,7 +2929,8 @@  discard block
 block discarded – undo
2502 2929
 		$inboxData->shortFolderName	= 'INBOX';
2503 2930
 		$inboxData->shortDisplayName	= lang('INBOX');
2504 2931
 		$inboxData->subscribed = true;
2505
-		if($_getCounters == true) {
2932
+		if($_getCounters == true)
2933
+		{
2506 2934
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2507 2935
 		}
2508 2936
 		// force unsubscribed by preference showAllFoldersInFolderPane
@@ -2521,12 +2949,14 @@  discard block
 block discarded – undo
2521 2949
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2522 2950
 		if (is_array($nameSpace))
2523 2951
 		{
2524
-			foreach($nameSpace as $k => $singleNameSpace) {
2952
+			foreach($nameSpace as $k => $singleNameSpace)
2953
+			{
2525 2954
 				$type = $singleNameSpace['type'];
2526 2955
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2527 2956
 				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2528 2957
 
2529
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
2958
+				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false)
2959
+				{
2530 2960
 					// fetch and sort the subscribed folders
2531 2961
 					// we alway fetch the subscribed, as this provides the only way to tell
2532 2962
 					// if a folder is subscribed or not
@@ -2577,8 +3007,12 @@  discard block
 block discarded – undo
2577 3007
 							}
2578 3008
 						}
2579 3009
 						//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($foldersNameSpace[$type]['subscribed']));
2580
-						if (!is_array($foldersNameSpace[$type]['all'])) $foldersNameSpace[$type]['all'] = array();
2581
-						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) {
3010
+						if (!is_array($foldersNameSpace[$type]['all']))
3011
+						{
3012
+							$foldersNameSpace[$type]['all'] = array();
3013
+						}
3014
+						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed']))
3015
+						{
2582 3016
 							continue;
2583 3017
 						}
2584 3018
 
@@ -2608,7 +3042,8 @@  discard block
 block discarded – undo
2608 3042
 					}
2609 3043
 
2610 3044
 					//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($allMailboxesExt));
2611
-					foreach ($allMailboxesExt as $mbx) {
3045
+					foreach ($allMailboxesExt as $mbx)
3046
+					{
2612 3047
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2613 3048
 						{
2614 3049
 							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
@@ -2631,20 +3066,33 @@  discard block
 block discarded – undo
2631 3066
 						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2632 3067
 							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2633 3068
 							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2634
-						) continue;
3069
+						)
3070
+						{
3071
+							continue;
3072
+						}
2635 3073
 
2636 3074
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
2637 3075
 						$allMailBoxesExtSorted[$mbx['MAILBOX']] = $mbx;
2638 3076
 					}
2639
-					if (is_array($allMailBoxesExtSorted)) ksort($allMailBoxesExtSorted);
3077
+					if (is_array($allMailBoxesExtSorted))
3078
+					{
3079
+						ksort($allMailBoxesExtSorted);
3080
+					}
2640 3081
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2641 3082
 					$allMailboxes = array();
2642
-					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2643
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
3083
+					foreach ((array)$allMailBoxesExtSorted as $mbx)
3084
+					{
3085
+						if (!in_array($mbx['MAILBOX'],$allMailboxes))
3086
+						{
3087
+							$allMailboxes[] = $mbx['MAILBOX'];
3088
+						}
2644 3089
 						//echo "Result:";_debug_array($allMailboxes);
2645 3090
 					}
2646 3091
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
2647
-					if (is_array($foldersNameSpace[$type]['all'])) sort($foldersNameSpace[$type]['all']);
3092
+					if (is_array($foldersNameSpace[$type]['all']))
3093
+					{
3094
+						sort($foldersNameSpace[$type]['all']);
3095
+					}
2648 3096
 				}
2649 3097
 			}
2650 3098
 		}
@@ -2653,24 +3101,50 @@  discard block
 block discarded – undo
2653 3101
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2654 3102
 		$autoFolderObjects = $folders = array();
2655 3103
 		$autofolder_exists = array();
2656
-		foreach( array('personal', 'others', 'shared') as $type) {
2657
-			if(isset($foldersNameSpace[$type])) {
2658
-				if($_subscribedOnly) {
2659
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2660
-				} else {
2661
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2662
-				}
2663
-				foreach((array)$listOfFolders as $folderName) {
3104
+		foreach( array('personal', 'others', 'shared') as $type)
3105
+		{
3106
+			if(isset($foldersNameSpace[$type]))
3107
+			{
3108
+				if($_subscribedOnly)
3109
+				{
3110
+					if( !empty($foldersNameSpace[$type]['subscribed']) )
3111
+					{
3112
+						$listOfFolders = $foldersNameSpace[$type]['subscribed'];
3113
+					}
3114
+				}
3115
+				else
3116
+				{
3117
+					if( !empty($foldersNameSpace[$type]['all']))
3118
+					{
3119
+						$listOfFolders = $foldersNameSpace[$type]['all'];
3120
+					}
3121
+				}
3122
+				foreach((array)$listOfFolders as $folderName)
3123
+				{
2664 3124
 					//echo "<br>FolderToCheck:$folderName<br>";
2665 3125
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2666
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2667
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
3126
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all']))
3127
+					{
3128
+						continue;
3129
+					}
3130
+					//when subscribedonly, we fetch all folders in one go.
3131
+					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all'])))
3132
+					{
2668 3133
 						#echo "$folderName failed to be here <br>";
2669 3134
 						continue;
2670 3135
 					}
2671
-					if (isset($folders[$folderName])) continue;
2672
-					if (isset($autoFolderObjects[$folderName])) continue;
2673
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
3136
+					if (isset($folders[$folderName]))
3137
+					{
3138
+						continue;
3139
+					}
3140
+					if (isset($autoFolderObjects[$folderName]))
3141
+					{
3142
+						continue;
3143
+					}
3144
+					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter'])
3145
+					{
3146
+						$delimiter = $foldersNameSpace[$type]['delimiter'];
3147
+					}
2674 3148
 					$folderParts = explode($delimiter, $folderName);
2675 3149
 					$shortName = array_pop($folderParts);
2676 3150
 
@@ -2678,17 +3152,20 @@  discard block
 block discarded – undo
2678 3152
 					$folderObject->delimiter	= $delimiter;
2679 3153
 					$folderObject->folderName	= $folderName;
2680 3154
 					$folderObject->shortFolderName	= $shortName;
2681
-					if(!$_subscribedOnly) {
3155
+					if(!$_subscribedOnly)
3156
+					{
2682 3157
 						#echo $folderName."->".$type."<br>";
2683 3158
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2684 3159
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2685 3160
 					}
2686 3161
 
2687
-					if($_getCounters == true) {
3162
+					if($_getCounters == true)
3163
+					{
2688 3164
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2689 3165
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2690 3166
 					}
2691
-					if(strtoupper($folderName) == 'INBOX') {
3167
+					if(strtoupper($folderName) == 'INBOX')
3168
+					{
2692 3169
 						$folderName = 'INBOX';
2693 3170
 						$folderObject->folderName	= 'INBOX';
2694 3171
 						$folderObject->shortFolderName	= 'INBOX';
@@ -2696,24 +3173,34 @@  discard block
 block discarded – undo
2696 3173
 						$folderObject->shortDisplayName = lang('INBOX');
2697 3174
 						$folderObject->subscribed	= true;
2698 3175
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2699
-					} elseif (in_array($shortName,self::$autoFolders)) {
3176
+					}
3177
+					elseif (in_array($shortName,self::$autoFolders))
3178
+					{
2700 3179
 						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2701 3180
 						array_pop($tmpfolderparts);
2702 3181
 						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2703 3182
 						$folderObject->shortDisplayName = lang($shortName);
2704 3183
 						unset($tmpfolderparts);
2705
-					} else {
3184
+					}
3185
+					else
3186
+					{
2706 3187
 						$folderObject->displayName = $folderObject->folderName;
2707 3188
 						$folderObject->shortDisplayName = $shortName;
2708 3189
 					}
2709 3190
 					//$folderName = $folderName;
2710
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
3191
+					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false)
3192
+					{
2711 3193
 						$autoFolderObjects[$folderName] = $folderObject;
2712
-					} else {
3194
+					}
3195
+					else
3196
+					{
2713 3197
 						$folders[$folderName] = $folderObject;
2714 3198
 					}
2715 3199
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2716
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
3200
+					if (!isset(self::$specialUseFolders))
3201
+					{
3202
+						$this->getSpecialUseFolders ();
3203
+					}
2717 3204
 					if (isset(self::$specialUseFolders[$folderName]))
2718 3205
 					{
2719 3206
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2721,7 +3208,8 @@  discard block
 block discarded – undo
2721 3208
 				}
2722 3209
 			}
2723 3210
 		}
2724
-		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
3211
+		if (is_array($autoFolderObjects) && !empty($autoFolderObjects))
3212
+		{
2725 3213
 			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2726 3214
 		}
2727 3215
 		// check if some standard folders are missing and need to be created
@@ -2730,7 +3218,10 @@  discard block
 block discarded – undo
2730 3218
 			// if new folders have been created, re-read folders ignoring the cache
2731 3219
 			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2732 3220
 		}
2733
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
3221
+		if (is_array($folders))
3222
+		{
3223
+			uasort($folders,array($this,"sortByDisplayName"));
3224
+		}
2734 3225
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2735 3226
 		//_debug_array($folders2return); #exit;
2736 3227
 		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
@@ -2742,7 +3233,10 @@  discard block
 block discarded – undo
2742 3233
 			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2743 3234
 		}
2744 3235
 		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2745
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3236
+		if (self::$debugTimes)
3237
+		{
3238
+			self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3239
+		}
2746 3240
 		return $folders2return[$this->icServer->ImapServerId];
2747 3241
 	}
2748 3242
 
@@ -2770,31 +3264,44 @@  discard block
 block discarded – undo
2770 3264
 
2771 3265
 		$folders = $nameSpace =  array();
2772 3266
 		$nameSpaceTmp = $this->_getNameSpaces();
2773
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
3267
+		foreach($nameSpaceTmp as $k => $singleNameSpace)
3268
+		{
2774 3269
 			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2775 3270
 		}
2776 3271
 		unset($nameSpaceTmp);
2777 3272
 
2778 3273
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2779 3274
 		// Get special use folders
2780
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
3275
+		if (!isset(self::$specialUseFolders))
3276
+		{
3277
+			$this->getSpecialUseFolders ();
3278
+		}
3279
+		// Set self::$specialUseFolders
2781 3280
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2782
-		if ($_onlyTopLevel) // top level leaves
3281
+		if ($_onlyTopLevel)
3282
+		{
3283
+			// top level leaves
2783 3284
 		{
2784 3285
 			// Get top mailboxes of icServer
2785 3286
 			$topFolders = $this->icServer->getMailboxes("", 2, true);
3287
+		}
2786 3288
 			// Trigger examination of namespace to retrieve
2787 3289
 			// folders located in other and shared; needed only for some servers
2788
-			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
3290
+			if (is_null(self::$mailConfig))
3291
+			{
3292
+				self::$mailConfig = Config::read('mail');
3293
+			}
2789 3294
 			if (self::$mailConfig['examineNamespace'])
2790 3295
 			{
2791 3296
 				$prefixes=array();
2792 3297
 				if (is_array($nameSpace))
2793 3298
 				{
2794
-					foreach($nameSpace as $k => $singleNameSpace) {
3299
+					foreach($nameSpace as $k => $singleNameSpace)
3300
+					{
2795 3301
 						$type = $singleNameSpace['type'];
2796 3302
 
2797
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
3303
+						if(is_array($singleNameSpace) && $singleNameSpace['prefix'])
3304
+						{
2798 3305
 							$prefixes[$type] = $singleNameSpace['prefix'];
2799 3306
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2800 3307
 							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
@@ -2870,7 +3377,10 @@  discard block
 block discarded – undo
2870 3377
 							$nFolders [$path] = $folder;
2871 3378
 						}
2872 3379
 					}
2873
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
3380
+					if (is_array($aFolders))
3381
+					{
3382
+						uasort ($aFolders, array($this,'sortByAutofolder'));
3383
+					}
2874 3384
 					//ksort($aFolders);
2875 3385
 
2876 3386
 					// Sort none auto folders base on mailbox name
@@ -2880,12 +3390,17 @@  discard block
 block discarded – undo
2880 3390
 				}
2881 3391
 				else
2882 3392
 				{
2883
-					if (is_array($subFolders)) ksort($subFolders);
3393
+					if (is_array($subFolders))
3394
+					{
3395
+						ksort($subFolders);
3396
+					}
2884 3397
 				}
2885 3398
 				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2886 3399
 			}
2887 3400
 		}
2888
-		elseif ($_nodePath) // single node
3401
+		elseif ($_nodePath)
3402
+		{
3403
+			// single node
2889 3404
 		{
2890 3405
 			switch ($_search)
2891 3406
 			{
@@ -2893,6 +3408,7 @@  discard block
 block discarded – undo
2893 3408
 				case 0:
2894 3409
 				case 2:
2895 3410
 					$path = $_nodePath.''.$delimiter;
3411
+		}
2896 3412
 					break;
2897 3413
 				// Node itself
2898 3414
 				// shouldn't contain next level delimiter
@@ -2911,11 +3427,14 @@  discard block
 block discarded – undo
2911 3427
 
2912 3428
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2913 3429
 		}
2914
-		elseif(!$_nodePath) // all
3430
+		elseif(!$_nodePath)
3431
+		{
3432
+			// all
2915 3433
 		{
2916 3434
 			if ($_subscribedOnly)
2917 3435
 			{
2918 3436
 				$folders = $this->icServer->listSubscribedMailboxes('', 0, true);
3437
+		}
2919 3438
 			}
2920 3439
 			else
2921 3440
 			{
@@ -2927,7 +3446,10 @@  discard block
 block discarded – undo
2927 3446
 		{
2928 3447
 			// SORTING FOLDERS
2929 3448
 			//self::$debugTimes=true;
2930
-			if (self::$debugTimes) $starttime = microtime (true);
3449
+			if (self::$debugTimes)
3450
+			{
3451
+				$starttime = microtime (true);
3452
+			}
2931 3453
 			// Merge of all auto folders and specialusefolders
2932 3454
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
2933 3455
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
@@ -2937,73 +3459,103 @@  discard block
 block discarded – undo
2937 3459
 			$isGoogleMail=false;
2938 3460
 			foreach($autoFoldersTmp as $afk=>$aF)
2939 3461
 			{
2940
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3462
+				if (!isset($mySpecialUseFolders[$aF]) && $aF)
3463
+				{
3464
+					$mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3465
+				}
2941 3466
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2942 3467
 			}
2943 3468
 			//error_log(array2string($mySpecialUseFolders));
2944
-			foreach ($tmpFolders as $k => $f) {
3469
+			foreach ($tmpFolders as $k => $f)
3470
+			{
2945 3471
 				$sorted=false;
2946
-				if (strtoupper(substr($k,0,5))=='INBOX') {
2947
-					if (strtoupper($k)=='INBOX') {
3472
+				if (strtoupper(substr($k,0,5))=='INBOX')
3473
+				{
3474
+					if (strtoupper($k)=='INBOX')
3475
+					{
2948 3476
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
2949 3477
 						$inboxFolderObject[$k]=$f;
2950 3478
 						unset($folders[$k]);
2951 3479
 						$sorted=true;
2952
-					} else {
3480
+					}
3481
+					else
3482
+					{
2953 3483
 						$isAutoFolder=false;
2954 3484
 						foreach($autoFoldersTmp as $afk=>$aF)
2955 3485
 						{
2956 3486
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2957 3487
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2958 3488
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
2959
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3489
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3490
+							{
3491
+								// k is parent of an autofolder
2960 3492
 							{
2961 3493
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
2962 3494
 								$isAutoFolder=true;
3495
+							}
2963 3496
 								$autoFolderObjects[$k]=$f;
2964 3497
 								break;
2965 3498
 							}
2966 3499
 						}
2967
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3500
+						if ($isAutoFolder==false)
3501
+						{
3502
+							$inboxSubFolderObjects[$k]=$f;
3503
+						}
2968 3504
 						unset($folders[$k]);
2969 3505
 						$sorted=true;
2970 3506
 					}
2971
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3507
+				}
3508
+				elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]')
3509
+				{
2972 3510
 					$isGoogleMail=true;
2973
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3511
+					if (strtoupper($k)=='[GOOGLE MAIL]')
3512
+					{
2974 3513
 						$googleMailFolderObject[$k]=$f;
2975 3514
 						unset($folders[$k]);
2976 3515
 						$sorted=true;
2977
-					} else {
3516
+					}
3517
+					else
3518
+					{
2978 3519
 						$isAutoFolder=false;
2979 3520
 						foreach($autoFoldersTmp as $afk=>$aF)
2980 3521
 						{
2981 3522
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2982 3523
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2983 3524
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
2984
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3525
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3526
+							{
3527
+								// k is parent of an autofolder
2985 3528
 							{
2986 3529
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
2987 3530
 								$isAutoFolder=true;
3531
+							}
2988 3532
 								$googleAutoFolderObjects[$k]=$f;
2989 3533
 								break;
2990 3534
 							}
2991 3535
 						}
2992
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3536
+						if ($isAutoFolder==false)
3537
+						{
3538
+							$googleSubFolderObjects[$k]=$f;
3539
+						}
2993 3540
 						unset($folders[$k]);
2994 3541
 						$sorted=true;
2995 3542
 					}
2996
-				} else {
3543
+				}
3544
+				else
3545
+				{
2997 3546
 					$isAutoFolder=false;
2998 3547
 					foreach($autoFoldersTmp as $afk=>$aF)
2999 3548
 					{
3000 3549
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3001 3550
 						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3002 3551
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3003
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3552
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3553
+						{
3554
+							// k is parent of an autofolder
3004 3555
 						{
3005 3556
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3006 3557
 							$isAutoFolder=true;
3558
+						}
3007 3559
 							$autoFolderObjects[$k]=$f;
3008 3560
 							unset($folders[$k]);
3009 3561
 							$sorted=true;
@@ -3019,7 +3571,8 @@  discard block
 block discarded – undo
3019 3571
 						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3020 3572
 						{
3021 3573
 							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3022
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3574
+								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1))
3575
+							{
3023 3576
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3024 3577
 								$typeFolderObject[$type][$k]=$f;
3025 3578
 								unset($folders[$k]);
@@ -3046,9 +3599,12 @@  discard block
 block discarded – undo
3046 3599
 				}
3047 3600
 			}
3048 3601
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3049
-			if (!$isGoogleMail) {
3602
+			if (!$isGoogleMail)
3603
+			{
3050 3604
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3051
-			} else {
3605
+			}
3606
+			else
3607
+			{
3052 3608
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3053 3609
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3054 3610
 				unset($googleAutoFolderObjects);
@@ -3065,7 +3621,10 @@  discard block
 block discarded – undo
3065 3621
 				}
3066 3622
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3067 3623
 			}
3068
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3624
+			if (self::$debugTimes)
3625
+			{
3626
+				self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3627
+			}
3069 3628
 			//self::$debugTimes=false;
3070 3629
 		}
3071 3630
 		// Get counter information and add them to each fetched folders array
@@ -3115,7 +3674,13 @@  discard block
 block discarded – undo
3115 3674
 		$rv = false;
3116 3675
 		foreach ($haystack as $k => $v)
3117 3676
 		{
3118
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3677
+			foreach($v as &$sv)
3678
+			{
3679
+if (trim($sv)==trim($needle))
3680
+			{
3681
+				return $k;
3682
+			}
3683
+			}
3119 3684
 		}
3120 3685
 		return $rv;
3121 3686
 	}
@@ -3142,7 +3707,10 @@  discard block
 block discarded – undo
3142 3707
 	 */
3143 3708
 	static function pathToFolderData ($_path, $_hDelimiter)
3144 3709
 	{
3145
-		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3710
+		if (!strpos($_path, self::DELIMITER))
3711
+		{
3712
+			$_path = self::DELIMITER.$_path;
3713
+		}
3146 3714
 		list(,$path) = explode(self::DELIMITER, $_path);
3147 3715
 		$path_chain = $parts = explode($_hDelimiter, $path);
3148 3716
 		$name = array_pop($parts);
@@ -3171,7 +3739,10 @@  discard block
 block discarded – undo
3171 3739
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3172 3740
 		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3173 3741
 		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3174
-		if ($pos1 == $pos2) return 0;
3742
+		if ($pos1 == $pos2)
3743
+		{
3744
+			return 0;
3745
+		}
3175 3746
 		return ($pos1 < $pos2) ? -1 : 1;
3176 3747
 	}
3177 3748
 
@@ -3202,7 +3773,10 @@  discard block
 block discarded – undo
3202 3773
 		// 0, 1 und -1
3203 3774
 		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3204 3775
 		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3205
-		if ($pos1 == $pos2) return 0;
3776
+		if ($pos1 == $pos2)
3777
+		{
3778
+			return 0;
3779
+		}
3206 3780
 		return ($pos1 < $pos2) ? -1 : 1;
3207 3781
 	}
3208 3782
 
@@ -3223,11 +3797,18 @@  discard block
 block discarded – undo
3223 3797
 		}
3224 3798
 		catch (\Exception $e)
3225 3799
 		{
3226
-			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3800
+			if (self::$debug)
3801
+			{
3802
+				error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3803
+			}
3227 3804
 			return false;
3228 3805
 		}
3229
-		if(is_array($folderStatus)) {
3230
-			if ($_returnObject===false) return $folderStatus;
3806
+		if(is_array($folderStatus))
3807
+		{
3808
+			if ($_returnObject===false)
3809
+			{
3810
+				return $folderStatus;
3811
+			}
3231 3812
 			$status =  new \stdClass;
3232 3813
 			$status->messages   = $folderStatus['MESSAGES'];
3233 3814
 			$status->unseen     = $folderStatus['UNSEEN'];
@@ -3254,7 +3835,8 @@  discard block
 block discarded – undo
3254 3835
 	{
3255 3836
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3256 3837
 		$maxreclevel=25;
3257
-		if ($reclevel > $maxreclevel) {
3838
+		if ($reclevel > $maxreclevel)
3839
+		{
3258 3840
 			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3259 3841
 			return array();
3260 3842
 		}
@@ -3268,7 +3850,8 @@  discard block
 block discarded – undo
3268 3850
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3269 3851
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3270 3852
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3271
-		if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) {
3853
+		if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
3854
+		{
3272 3855
 			// if there are children fetch them
3273 3856
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3274 3857
 
@@ -3276,7 +3859,8 @@  discard block
 block discarded – undo
3276 3859
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3277 3860
 			//_debug_array($buff);
3278 3861
 			$allMailboxes = array();
3279
-			foreach ($buff as $mbxname) {
3862
+			foreach ($buff as $mbxname)
3863
+			{
3280 3864
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3281 3865
 				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3282 3866
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
@@ -3285,9 +3869,14 @@  discard block
 block discarded – undo
3285 3869
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3286 3870
 				}
3287 3871
 			}
3288
-			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3872
+			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
3873
+			{
3874
+				$allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3875
+			}
3289 3876
 			return $allMailboxes;
3290
-		} else {
3877
+		}
3878
+		else
3879
+		{
3291 3880
 			return array($_mailbox);
3292 3881
 		}
3293 3882
 	}
@@ -3311,14 +3900,21 @@  discard block
 block discarded – undo
3311 3900
 			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3312 3901
 			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3313 3902
 		);
3314
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3903
+		if ($_type == 'Templates')
3904
+		{
3905
+			$_type = 'Template';
3906
+		}
3907
+		// for some reason self::$autofolders uses 'Templates'!
3315 3908
 		$created = false;
3316 3909
 		if (!isset($types[$_type]))
3317 3910
 		{
3318 3911
 			error_log(__METHOD__.' ('.__LINE__.') '.' '.$_type.' not supported for '.__METHOD__);
3319 3912
 			return false;
3320 3913
 		}
3321
-		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) self::$specialUseFolders = $this->getSpecialUseFolders();
3914
+		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders))
3915
+		{
3916
+			self::$specialUseFolders = $this->getSpecialUseFolders();
3917
+		}
3322 3918
 
3323 3919
 		//highest precedence
3324 3920
 		try
@@ -3328,25 +3924,39 @@  discard block
 block discarded – undo
3328 3924
 		catch (\Exception $e)
3329 3925
 		{
3330 3926
 			// we know that outbox is not supported, but we use this here, as we autocreate expected SpecialUseFolders in this function
3331
-			if ($_type != 'Outbox') error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3927
+			if ($_type != 'Outbox')
3928
+			{
3929
+				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3930
+			}
3332 3931
 			$_folderName = false;
3333 3932
 		}
3334 3933
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3335
-		if ($_type == 'Archive') {
3336
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3934
+		if ($_type == 'Archive')
3935
+		{
3936
+			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
3937
+			{
3337 3938
 				return false;
3338
-			} else {
3939
+			}
3940
+			else
3941
+			{
3339 3942
 				return $_folderName;
3340 3943
 			}
3341 3944
 
3342 3945
 		}
3343 3946
 		// does the folder exist??? (is configured/preset, but non-existent)
3344
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3947
+		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
3948
+		{
3345 3949
 			try
3346 3950
 			{
3347 3951
 				$error = null;
3348
-				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3349
-				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3952
+				if (($_folderName = $this->createFolder('', $_folderName, $error)))
3953
+				{
3954
+					$created = true;
3955
+				}
3956
+				if ($error)
3957
+				{
3958
+					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3959
+				}
3350 3960
 			}
3351 3961
 			catch(Exception $e)
3352 3962
 			{
@@ -3355,9 +3965,16 @@  discard block
 block discarded – undo
3355 3965
 			}
3356 3966
 		}
3357 3967
 		// not sure yet if false is the correct behavior on none
3358
-		if ($_folderName =='none') return 'none' ; //false;
3968
+		if ($_folderName =='none')
3969
+		{
3970
+			return 'none' ;
3971
+		}
3972
+		//false;
3359 3973
 		//no (valid) folder found yet; try specialUseFolders
3360
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
3974
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders)))
3975
+		{
3976
+			$_folderName = $f;
3977
+		}
3361 3978
 		//no specialUseFolder; try some Defaults
3362 3979
 		if (empty($_folderName) && isset($types[$_type]))
3363 3980
 		{
@@ -3383,7 +4000,10 @@  discard block
 block discarded – undo
3383 4000
 					$error = null;
3384 4001
 					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3385 4002
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3386
-					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4003
+					if ($error)
4004
+					{
4005
+						error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4006
+					}
3387 4007
 				}
3388 4008
 				catch(Exception $e)
3389 4009
 				{
@@ -3485,17 +4105,22 @@  discard block
 block discarded – undo
3485 4105
 	function isSentFolder($_folderName, $_checkexistance=TRUE)
3486 4106
 	{
3487 4107
 		$sentFolder = $this->getSentFolder($_checkexistance);
3488
-		if(empty($sentFolder)) {
4108
+		if(empty($sentFolder))
4109
+		{
3489 4110
 			return false;
3490 4111
 		}
3491 4112
 		// does the folder exist???
3492
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4113
+		if ($_checkexistance && !$this->folderExists($_folderName))
4114
+		{
3493 4115
 			return false;
3494 4116
 		}
3495 4117
 
3496
-		if(false !== stripos($_folderName, $sentFolder)) {
4118
+		if(false !== stripos($_folderName, $sentFolder))
4119
+		{
3497 4120
 			return true;
3498
-		} else {
4121
+		}
4122
+		else
4123
+		{
3499 4124
 			return false;
3500 4125
 		}
3501 4126
 	}
@@ -3508,15 +4133,20 @@  discard block
 block discarded – undo
3508 4133
 	 */
3509 4134
 	function isOutbox($_folderName, $_checkexistance=TRUE)
3510 4135
 	{
3511
-		if (stripos($_folderName, 'Outbox')===false) {
4136
+		if (stripos($_folderName, 'Outbox')===false)
4137
+		{
3512 4138
 			return false;
3513 4139
 		}
3514 4140
 		// does the folder exist???
3515
-		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
4141
+		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName))
4142
+		{
3516 4143
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3517
-			if(false !== stripos($_folderName, $outboxFolder)) {
4144
+			if(false !== stripos($_folderName, $outboxFolder))
4145
+			{
3518 4146
 				return true;
3519
-			} else {
4147
+			}
4148
+			else
4149
+			{
3520 4150
 				return false;
3521 4151
 			}
3522 4152
 		}
@@ -3532,17 +4162,25 @@  discard block
 block discarded – undo
3532 4162
 	function isDraftFolder($_folderName, $_checkexistance=TRUE)
3533 4163
 	{
3534 4164
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3535
-		if(empty($draftFolder)) {
4165
+		if(empty($draftFolder))
4166
+		{
3536 4167
 			return false;
3537 4168
 		}
3538 4169
 		// does the folder exist???
3539
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4170
+		if ($_checkexistance && !$this->folderExists($_folderName))
4171
+		{
3540 4172
 			return false;
3541 4173
 		}
3542
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3543
-		if(false !== stripos($_folderName, $draftFolder)) {
4174
+		if (is_a($_folderName,"Horde_Imap_Client_Mailbox"))
4175
+		{
4176
+			$_folderName = $_folderName->utf8;
4177
+		}
4178
+		if(false !== stripos($_folderName, $draftFolder))
4179
+		{
3544 4180
 			return true;
3545
-		} else {
4181
+		}
4182
+		else
4183
+		{
3546 4184
 			return false;
3547 4185
 		}
3548 4186
 	}
@@ -3556,17 +4194,22 @@  discard block
 block discarded – undo
3556 4194
 	function isTrashFolder($_folderName, $_checkexistance=TRUE)
3557 4195
 	{
3558 4196
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3559
-		if(empty($trashFolder)) {
4197
+		if(empty($trashFolder))
4198
+		{
3560 4199
 			return false;
3561 4200
 		}
3562 4201
 		// does the folder exist???
3563
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4202
+		if ($_checkexistance && !$this->folderExists($_folderName))
4203
+		{
3564 4204
 			return false;
3565 4205
 		}
3566 4206
 
3567
-		if(false !== stripos($_folderName, $trashFolder)) {
4207
+		if(false !== stripos($_folderName, $trashFolder))
4208
+		{
3568 4209
 			return true;
3569
-		} else {
4210
+		}
4211
+		else
4212
+		{
3570 4213
 			return false;
3571 4214
 		}
3572 4215
 	}
@@ -3580,17 +4223,22 @@  discard block
 block discarded – undo
3580 4223
 	function isTemplateFolder($_folderName, $_checkexistance=TRUE)
3581 4224
 	{
3582 4225
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3583
-		if(empty($templateFolder)) {
4226
+		if(empty($templateFolder))
4227
+		{
3584 4228
 			return false;
3585 4229
 		}
3586 4230
 		// does the folder exist???
3587
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4231
+		if ($_checkexistance && !$this->folderExists($_folderName))
4232
+		{
3588 4233
 			return false;
3589 4234
 		}
3590 4235
 
3591
-		if(false !== stripos($_folderName, $templateFolder)) {
4236
+		if(false !== stripos($_folderName, $templateFolder))
4237
+		{
3592 4238
 			return true;
3593
-		} else {
4239
+		}
4240
+		else
4241
+		{
3594 4242
 			return false;
3595 4243
 		}
3596 4244
 	}
@@ -3608,15 +4256,27 @@  discard block
 block discarded – undo
3608 4256
 		if (empty($_folder))
3609 4257
 		{
3610 4258
 			// this error is more or less without significance, unless we force the check
3611
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4259
+			if ($_forceCheck===true)
4260
+			{
4261
+				error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4262
+			}
3612 4263
 			return false;
3613 4264
 		}
3614 4265
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3615
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3616
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
4266
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false)
4267
+		{
4268
+			return true;
4269
+		}
4270
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox"))
4271
+		{
4272
+			$_folder =  $_folder->utf8;
4273
+		}
3617 4274
 		// reduce traffic within the Instance per User; Expire every 5 hours
3618 4275
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3619
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4276
+		if (is_null($folderInfo))
4277
+		{
4278
+			$folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4279
+		}
3620 4280
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3621 4281
 		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3622 4282
 		{
@@ -3634,7 +4294,8 @@  discard block
 block discarded – undo
3634 4294
 
3635 4295
 		// does the folder exist???
3636 4296
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3637
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
4297
+		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder]))
4298
+		{
3638 4299
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3639 4300
 			//return false;
3640 4301
 			//try to connect
@@ -3674,9 +4335,12 @@  discard block
 block discarded – undo
3674 4335
 
3675 4336
 		$this->icServer->openMailbox($folderName);
3676 4337
 
3677
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
4338
+		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash")
4339
+		{
3678 4340
 			$this->deleteMessages('all',$folderName,'remove_immediately');
3679
-		} else {
4341
+		}
4342
+		else
4343
+		{
3680 4344
 			$this->icServer->expunge($folderName);
3681 4345
 		}
3682 4346
 	}
@@ -3695,10 +4359,16 @@  discard block
 block discarded – undo
3695 4359
 	{
3696 4360
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3697 4361
 		$oldMailbox = '';
3698
-		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
4362
+		if (is_null($_folder) || empty($_folder))
4363
+		{
4364
+			$_folder = $this->sessionData['mailbox'];
4365
+		}
3699 4366
 		if (empty($_messageUID))
3700 4367
 		{
3701
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4368
+			if (self::$debug)
4369
+			{
4370
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4371
+			}
3702 4372
 			return false;
3703 4373
 		}
3704 4374
 		elseif ($_messageUID==='all')
@@ -3708,32 +4378,48 @@  discard block
 block discarded – undo
3708 4378
 		else
3709 4379
 		{
3710 4380
 			$uidsToDelete = new Horde_Imap_Client_Ids();
3711
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4381
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4382
+			{
4383
+				$_messageUID = (array)$_messageUID;
4384
+			}
3712 4385
 			$uidsToDelete->add($_messageUID);
3713 4386
 		}
3714 4387
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3715
-		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately"))) $deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
4388
+		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately")))
4389
+		{
4390
+			$deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
4391
+		}
3716 4392
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3717 4393
 		$trashFolder    = $this->getTrashFolder();
3718 4394
 		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3719 4395
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3720 4396
 		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3721
-		   (strtolower($_folder) == strtolower($draftFolder))) {
4397
+		   (strtolower($_folder) == strtolower($draftFolder)))
4398
+		{
3722 4399
 			$deleteOptions = "remove_immediately";
3723 4400
 		}
3724
-		if($this->icServer->getCurrentMailbox() != $_folder) {
4401
+		if($this->icServer->getCurrentMailbox() != $_folder)
4402
+		{
3725 4403
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3726 4404
 			$this->icServer->openMailbox($_folder);
3727 4405
 		}
3728 4406
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3729 4407
 		$updateCache = false;
3730
-		switch($deleteOptions) {
4408
+		switch($deleteOptions)
4409
+		{
3731 4410
 			case "move_to_trash":
3732 4411
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3733 4412
 				$updateCache = true;
3734
-				if(!empty($trashFolder)) {
3735
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3736
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4413
+				if(!empty($trashFolder))
4414
+				{
4415
+					if (self::$debug)
4416
+					{
4417
+						error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
4418
+					}
4419
+					if (self::$debug)
4420
+					{
4421
+						error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4422
+					}
3737 4423
 					// copy messages
3738 4424
 					try
3739 4425
 					{
@@ -3749,7 +4435,10 @@  discard block
 block discarded – undo
3749 4435
 			case "mark_as_deleted":
3750 4436
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3751 4437
 				// mark messages as deleted
3752
-				if (is_null($_messageUID)) $_messageUID='all';
4438
+				if (is_null($_messageUID))
4439
+				{
4440
+					$_messageUID='all';
4441
+				}
3753 4442
 				foreach((array)$_messageUID as $key =>$uid)
3754 4443
 				{
3755 4444
 					//flag messages, that are flagged for deletion as seen too
@@ -3757,7 +4446,10 @@  discard block
 block discarded – undo
3757 4446
 					$flags = $this->getFlags($uid);
3758 4447
 					$this->flagMessages('delete', $uid, $_folder);
3759 4448
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3760
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
4449
+					if (strpos( array2string($flags),'Deleted')!==false)
4450
+					{
4451
+						$undelete[] = $uid;
4452
+					}
3761 4453
 					unset($flags);
3762 4454
 				}
3763 4455
 				foreach((array)$undelete as $key =>$uid)
@@ -3769,7 +4461,10 @@  discard block
 block discarded – undo
3769 4461
 			case "remove_immediately":
3770 4462
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3771 4463
 				$updateCache = true;
3772
-				if (is_null($_messageUID)) $_messageUID='all';
4464
+				if (is_null($_messageUID))
4465
+				{
4466
+					$_messageUID='all';
4467
+				}
3773 4468
 				if (is_object($_messageUID))
3774 4469
 				{
3775 4470
 					$this->flagMessages('delete', $_messageUID, $_folder);
@@ -3786,7 +4481,8 @@  discard block
 block discarded – undo
3786 4481
 				$this->icServer->expunge($_folder);
3787 4482
 				break;
3788 4483
 		}
3789
-		if($oldMailbox != '') {
4484
+		if($oldMailbox != '')
4485
+		{
3790 4486
 			$this->icServer->openMailbox($oldMailbox);
3791 4487
 		}
3792 4488
 
@@ -3800,11 +4496,15 @@  discard block
 block discarded – undo
3800 4496
 	 *
3801 4497
 	 * @return null/array flags
3802 4498
 	 */
3803
-	function getFlags ($_messageUID) {
4499
+	function getFlags ($_messageUID)
4500
+	{
3804 4501
 		try
3805 4502
 		{
3806 4503
 			$uidsToFetch = new Horde_Imap_Client_Ids();
3807
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4504
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4505
+			{
4506
+				$_messageUID = (array)$_messageUID;
4507
+			}
3808 4508
 			$uidsToFetch->add($_messageUID);
3809 4509
 			$_folderName = $this->icServer->getCurrentMailbox();
3810 4510
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -3812,8 +4512,10 @@  discard block
 block discarded – undo
3812 4512
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
3813 4513
 				'ids' => $uidsToFetch,
3814 4514
 			));
3815
-			if (is_object($headersNew)) {
3816
-				foreach($headersNew->ids() as $id) {
4515
+			if (is_object($headersNew))
4516
+			{
4517
+				foreach($headersNew->ids() as $id)
4518
+				{
3817 4519
 					$_headerObject = $headersNew->get($id);
3818 4520
 					$flags = $_headerObject->getFlags();
3819 4521
 				}
@@ -3838,10 +4540,16 @@  discard block
 block discarded – undo
3838 4540
 	 */
3839 4541
 	function getNotifyFlags ($_messageUID, $flags=null)
3840 4542
 	{
3841
-		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4543
+		if (self::$debug)
4544
+		{
4545
+			error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4546
+		}
3842 4547
 		try
3843 4548
 		{
3844
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
4549
+			if($flags===null)
4550
+			{
4551
+				$flags =  $this->getFlags($_messageUID);
4552
+			}
3845 4553
 		}
3846 4554
 		catch (\Exception $e)
3847 4555
 		{
@@ -3849,10 +4557,14 @@  discard block
 block discarded – undo
3849 4557
 		}
3850 4558
 
3851 4559
 		if ( stripos( array2string($flags),'MDNSent')!==false)
3852
-			return true;
4560
+		{
4561
+					return true;
4562
+		}
3853 4563
 
3854 4564
 		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3855
-			return false;
4565
+		{
4566
+					return false;
4567
+		}
3856 4568
 
3857 4569
 		return null;
3858 4570
 	}
@@ -3873,7 +4585,10 @@  discard block
 block discarded – undo
3873 4585
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3874 4586
 		if (empty($_messageUID))
3875 4587
 		{
3876
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4588
+			if (self::$debug)
4589
+			{
4590
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4591
+			}
3877 4592
 			return false;
3878 4593
 		}
3879 4594
 		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
@@ -3881,7 +4596,10 @@  discard block
 block discarded – undo
3881 4596
 		if (is_array($_messageUID)&& count($_messageUID)>50)
3882 4597
 		{
3883 4598
 			$count = $this->getMailBoxCounters($folder,true);
3884
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
4599
+			if ($count->messages == count($_messageUID))
4600
+			{
4601
+				$_messageUID='all';
4602
+			}
3885 4603
 		}
3886 4604
 
3887 4605
 		if ($_messageUID==='all')
@@ -3890,7 +4608,10 @@  discard block
 block discarded – undo
3890 4608
 		}
3891 4609
 		else
3892 4610
 		{
3893
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4611
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4612
+			{
4613
+				$_messageUID = (array)$_messageUID;
4614
+			}
3894 4615
 			$messageUIDs = array_chunk($_messageUID,50,true);
3895 4616
 		}
3896 4617
 		try
@@ -3906,7 +4627,8 @@  discard block
 block discarded – undo
3906 4627
 					$uidsToModify = new Horde_Imap_Client_Ids();
3907 4628
 					$uidsToModify->add($uids);
3908 4629
 				}
3909
-				switch($_flag) {
4630
+				switch($_flag)
4631
+				{
3910 4632
 					case "delete":
3911 4633
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
3912 4634
 						break;
@@ -3992,7 +4714,10 @@  discard block
 block discarded – undo
3992 4714
 		{
3993 4715
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
3994 4716
 		}
3995
-		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4717
+		if ($folder instanceof Horde_Imap_Client_Mailbox)
4718
+		{
4719
+			$_folder = $folder->utf8;
4720
+		}
3996 4721
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
3997 4722
 		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
3998 4723
 
@@ -4021,7 +4746,10 @@  discard block
 block discarded – undo
4021 4746
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4022 4747
 		if (empty($_messageUID))
4023 4748
 		{
4024
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4749
+			if (self::$debug)
4750
+			{
4751
+				error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4752
+			}
4025 4753
 			return false;
4026 4754
 		}
4027 4755
 		elseif ($_messageUID==='all')
@@ -4033,7 +4761,10 @@  discard block
 block discarded – undo
4033 4761
 		{
4034 4762
 			//error_log(__METHOD__." Message(s): ".implode(',',$_messageUID));
4035 4763
 			$uidsToMove = new Horde_Imap_Client_Ids();
4036
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4764
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4765
+			{
4766
+				$_messageUID = (array)$_messageUID;
4767
+			}
4037 4768
 			$uidsToMove->add($_messageUID);
4038 4769
 		}
4039 4770
 		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
@@ -4055,12 +4786,14 @@  discard block
 block discarded – undo
4055 4786
 
4056 4787
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4057 4788
 
4058
-			if (is_object($headersNew)) {
4789
+			if (is_object($headersNew))
4790
+			{
4059 4791
 				$c=0;
4060 4792
 				$retUid = new Horde_Imap_Client_Ids();
4061 4793
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4062 4794
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4063
-				foreach($headersNew as &$_headerObject) {
4795
+				foreach($headersNew as &$_headerObject)
4796
+				{
4064 4797
 					$c++;
4065 4798
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4066 4799
 					$date = $_headerObject->getImapDate();
@@ -4144,7 +4877,11 @@  discard block
 block discarded – undo
4144 4877
 	{
4145 4878
 		try {
4146 4879
 			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4147
-			if ($convert2usertime) $date->setUser();	// convert to user-time
4880
+			if ($convert2usertime)
4881
+			{
4882
+				$date->setUser();
4883
+			}
4884
+			// convert to user-time
4148 4885
 			$date2return = $date->format($format);
4149 4886
 		}
4150 4887
 		catch(\Exception $e)
@@ -4176,9 +4913,15 @@  discard block
 block discarded – undo
4176 4913
 	static function htmlentities($_string, $_charset=false)
4177 4914
 	{
4178 4915
 		//setting the charset (if not given)
4179
-		if ($_charset===false) $_charset = self::$displayCharset;
4916
+		if ($_charset===false)
4917
+		{
4918
+			$_charset = self::$displayCharset;
4919
+		}
4180 4920
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4181
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4921
+		if (empty($string) && !empty($_string))
4922
+		{
4923
+			$string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4924
+		}
4182 4925
 		return $string;
4183 4926
 	}
4184 4927
 
@@ -4198,18 +4941,41 @@  discard block
 block discarded – undo
4198 4941
 		$_html = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>','</td></font>','<br><td>','<tr></tr>','<o:p></o:p>','<o:p>','</o:p>'),
4199 4942
 							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4200 4943
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4201
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4202
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
4944
+		if (stripos($_html,'style')!==false)
4945
+		{
4946
+			Mail\Html::replaceTagsCompletley($_html,'style');
4947
+		}
4948
+		// clean out empty or pagewide style definitions / left over tags
4949
+		if (stripos($_html,'head')!==false)
4950
+		{
4951
+			Mail\Html::replaceTagsCompletley($_html,'head');
4952
+		}
4953
+		// Strip out stuff in head
4203 4954
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4204 4955
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4205 4956
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4206 4957
 
4207
-		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
4958
+		if (get_magic_quotes_gpc() === 1)
4959
+		{
4960
+			$_html = stripslashes($_html);
4961
+		}
4208 4962
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4209
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4210
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4211
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4212
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
4963
+		if (stripos($_html,'!doctype')!==false)
4964
+		{
4965
+			Mail\Html::replaceTagsCompletley($_html,'!doctype');
4966
+		}
4967
+		if (stripos($_html,'?xml:namespace')!==false)
4968
+		{
4969
+			Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4970
+		}
4971
+		if (stripos($_html,'?xml version')!==false)
4972
+		{
4973
+			Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4974
+		}
4975
+		if (strpos($_html,'!CURSOR')!==false)
4976
+		{
4977
+			Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
4978
+		}
4213 4979
 		// htmLawed filter only the 'body'
4214 4980
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4215 4981
 		//if ($matches[2])
@@ -4248,8 +5014,10 @@  discard block
 block discarded – undo
4248 5014
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4249 5015
 		$CharsetFound=false;
4250 5016
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4251
-		if(is_array($_mimePartObject->parameters)) {
4252
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
5017
+		if(is_array($_mimePartObject->parameters))
5018
+		{
5019
+			if(isset($_mimePartObject->parameters['CHARSET']))
5020
+			{
4253 5021
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4254 5022
 				$CharsetFound=true;
4255 5023
 			}
@@ -4270,7 +5038,10 @@  discard block
 block discarded – undo
4270 5038
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4271 5039
 	{
4272 5040
 		// decode the part
4273
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5041
+		if (self::$debug)
5042
+		{
5043
+			error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5044
+		}
4274 5045
 		switch (strtoupper($_encoding))
4275 5046
 		{
4276 5047
 			case 'BASE64':
@@ -4310,13 +5081,19 @@  discard block
 block discarded – undo
4310 5081
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4311 5082
 		// as attachment AND as abstracted ical information (we use our notification style here).
4312 5083
 		$partText = $partCalendar = $partHTML = null;
4313
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5084
+		if (self::$debug)
5085
+		{
5086
+			_debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5087
+		}
4314 5088
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4315 5089
 		$ignore_first_part = true;
4316 5090
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4317 5091
 		{
4318 5092
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4319
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5093
+			if (self::$debug)
5094
+			{
5095
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5096
+			}
4320 5097
 
4321 5098
 			if ($ignore_first_part)
4322 5099
 			{
@@ -4332,11 +5109,17 @@  discard block
 block discarded – undo
4332 5109
 					switch($mimePart->getSubType())
4333 5110
 					{
4334 5111
 						case 'plain':
4335
-							if ($mimePart->getBytes() > 0) $partText = $mimePart;
5112
+							if ($mimePart->getBytes() > 0)
5113
+							{
5114
+								$partText = $mimePart;
5115
+							}
4336 5116
 							break;
4337 5117
 
4338 5118
 						case 'html':
4339
-							if ($mimePart->getBytes() > 0)  $partHTML = $mimePart;
5119
+							if ($mimePart->getBytes() > 0)
5120
+							{
5121
+								$partHTML = $mimePart;
5122
+							}
4340 5123
 							break;
4341 5124
 					}
4342 5125
 					break;
@@ -4349,7 +5132,10 @@  discard block
 block discarded – undo
4349 5132
 							if (count($mimePart->getParts()) > 1)
4350 5133
 							{
4351 5134
 								// in a multipart alternative we treat the multipart/related as html part
4352
-								if (self::$debug) error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5135
+								if (self::$debug)
5136
+								{
5137
+									error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5138
+								}
4353 5139
 								$partHTML = $mimePart;
4354 5140
 								break 3; // GET OUT OF LOOP, will be processed according to type
4355 5141
 							}
@@ -4430,9 +5216,15 @@  discard block
 block discarded – undo
4430 5216
 	 */
4431 5217
 	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4432 5218
 	{
4433
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
5219
+		if (self::$debug)
5220
+		{
5221
+			echo __METHOD__."$_uid, $_htmlMode<br>";
5222
+		}
4434 5223
 		$bodyPart = array();
4435
-		if (self::$debug) _debug_array($_structure);
5224
+		if (self::$debug)
5225
+		{
5226
+			_debug_array($_structure);
5227
+		}
4436 5228
 
4437 5229
 		$ignore_first_part = true;
4438 5230
 		//$skipParts = array();
@@ -4440,7 +5232,10 @@  discard block
 block discarded – undo
4440 5232
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4441 5233
 		{
4442 5234
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4443
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5235
+			if (self::$debug)
5236
+			{
5237
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5238
+			}
4444 5239
 			if ($ignore_first_part)
4445 5240
 			{
4446 5241
 				$ignore_first_part = false;
@@ -4458,7 +5253,10 @@  discard block
 block discarded – undo
4458 5253
 			switch($part->getPrimaryType())
4459 5254
 			{
4460 5255
 				case 'multipart':
4461
-					if ($part->getDisposition() == 'attachment') continue;
5256
+					if ($part->getDisposition() == 'attachment')
5257
+					{
5258
+						continue;
5259
+					}
4462 5260
 					switch($part->getSubType())
4463 5261
 					{
4464 5262
 						case 'alternative':
@@ -4523,7 +5321,9 @@  discard block
 block discarded – undo
4523 5321
 					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4524 5322
 					{
4525 5323
 						$skipParts[$mime_id.'.0'] = $mime_type;
4526
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
5324
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
5325
+						{
5326
+$skipParts[$sub_id] = $sub_type;}
4527 5327
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4528 5328
 						//break 2;
4529 5329
 					}
@@ -4566,7 +5366,10 @@  discard block
 block discarded – undo
4566 5366
 	 */
4567 5367
 	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4568 5368
 	{
4569
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5369
+		if (self::$debug)
5370
+		{
5371
+			error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5372
+		}
4570 5373
 
4571 5374
 		if (empty($_folder))
4572 5375
 		{
@@ -4575,7 +5378,10 @@  discard block
 block discarded – undo
4575 5378
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4576 5379
 		// querying contents of body part
4577 5380
 		$uidsToFetch = new Horde_Imap_Client_Ids();
4578
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5381
+		if (!(is_object($_uid) || is_array($_uid)))
5382
+		{
5383
+			$_uid = (array)$_uid;
5384
+		}
4579 5385
 		$uidsToFetch->add($_uid);
4580 5386
 
4581 5387
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -4583,9 +5389,12 @@  discard block
 block discarded – undo
4583 5389
 			'peek' => $_preserveSeen,
4584 5390
 			'decode' => true,	// try decode on server, does NOT neccessary work
4585 5391
 		);
4586
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
5392
+		if ($_tryDecodingServerside===false)
5393
+		{
5394
+			// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4587 5395
 		{
4588 5396
 			$_tryDecodingServerside=false;
5397
+		}
4589 5398
 			$fetchParams = array(
4590 5399
 				'peek' => $_preserveSeen,
4591 5400
 			);
@@ -4627,7 +5436,10 @@  discard block
 block discarded – undo
4627 5436
 	{
4628 5437
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4629 5438
 		$bodyPart = array();
4630
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
5439
+		if (self::$debug)
5440
+		{
5441
+			_debug_array(array($_structure,function_backtrace()));
5442
+		}
4631 5443
 
4632 5444
 		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4633 5445
 		{
@@ -4677,8 +5489,12 @@  discard block
 block discarded – undo
4677 5489
 	 */
4678 5490
 	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4679 5491
 	{
4680
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4681
-		if($_htmlOptions != '') {
5492
+		if (self::$debug)
5493
+		{
5494
+			echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
5495
+		}
5496
+		if($_htmlOptions != '')
5497
+		{
4682 5498
 			$this->htmlOptions = $_htmlOptions;
4683 5499
 		}
4684 5500
 		if (empty($_folder))
@@ -4767,7 +5583,9 @@  discard block
 block discarded – undo
4767 5583
 						default:
4768 5584
 							$bodyPart = array($this->getTextPart($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
4769 5585
 					}
4770
-				} else {
5586
+				}
5587
+				else
5588
+				{
4771 5589
 					// what if the structure->disposition is attachment ,...
4772 5590
 				}
4773 5591
 				return self::normalizeBodyParts($bodyPart);
@@ -4778,13 +5596,18 @@  discard block
 block discarded – undo
4778 5596
 				{
4779 5597
 					case 'rfc822':
4780 5598
 						$newStructure = $_structure->getParts();
4781
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
5599
+						if (self::$debug)
5600
+						{
5601
+echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4782 5602
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4783 5603
 				}
4784 5604
 				break;
4785 5605
 
4786 5606
 			default:
4787
-				if (self::$debug) _debug_array($_structure);
5607
+				if (self::$debug)
5608
+				{
5609
+					_debug_array($_structure);
5610
+				}
4788 5611
 				return array(
4789 5612
 					array(
4790 5613
 						'body'		=> lang('The mimeparser can not parse this message.').$_structure->getType(),
@@ -4808,9 +5631,12 @@  discard block
 block discarded – undo
4808 5631
 		{
4809 5632
 			foreach($_bodyParts as $singleBodyPart)
4810 5633
 			{
4811
-				if (!isset($singleBodyPart['body'])) {
5634
+				if (!isset($singleBodyPart['body']))
5635
+				{
4812 5636
 					$buff = self::normalizeBodyParts($singleBodyPart);
4813
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
5637
+					foreach ((array)$buff as $val)
5638
+					{
5639
+$body2return[] = $val;}
4814 5640
 					continue;
4815 5641
 				}
4816 5642
 				$body2return[] = $singleBodyPart;
@@ -4836,13 +5662,20 @@  discard block
 block discarded – undo
4836 5662
 		$message='';
4837 5663
 		for($i=0; $i<count($bodyParts); $i++)
4838 5664
 		{
4839
-			if (!isset($bodyParts[$i]['body'])) {
5665
+			if (!isset($bodyParts[$i]['body']))
5666
+			{
4840 5667
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4841 5668
 				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4842 5669
 				continue;
4843 5670
 			}
4844
-			if (isset($bodyParts[$i]['error'])) continue;
4845
-			if (empty($bodyParts[$i]['body'])) continue;
5671
+			if (isset($bodyParts[$i]['error']))
5672
+			{
5673
+				continue;
5674
+			}
5675
+			if (empty($bodyParts[$i]['body']))
5676
+			{
5677
+				continue;
5678
+			}
4846 5679
 			// some characterreplacements, as they fail to translate
4847 5680
 			$sar = array(
4848 5681
 				'@(\x84|\x93|\x94)@',
@@ -4869,13 +5702,17 @@  discard block
 block discarded – undo
4869 5702
 				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4870 5703
 			}
4871 5704
 
4872
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5705
+			if ($bodyParts[$i]['charSet']===false)
5706
+			{
5707
+				$bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5708
+			}
4873 5709
 			// add line breaks to $bodyParts
4874 5710
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4875 5711
 			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4876 5712
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4877 5713
 			$mailClass->activeMimeType = 'text/plain';
4878
-			if ($bodyParts[$i]['mimeType'] == 'text/html') {
5714
+			if ($bodyParts[$i]['mimeType'] == 'text/html')
5715
+			{
4879 5716
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4880 5717
 				if (!$preserveHTML)
4881 5718
 				{
@@ -4921,15 +5758,28 @@  discard block
 block discarded – undo
4921 5758
 						// as we switched off HTMLaweds tidy functionality
4922 5759
 						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
4923 5760
 						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
4924
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
5761
+						if ($hasOther && $preserveHTML)
5762
+						{
5763
+							$newBody = $matches[1]. $newBody. $matches[3];
5764
+						}
4925 5765
 						$alreadyHtmlLawed=true;
4926 5766
 					}
4927 5767
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
4928
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5768
+					if ($preserveHTML==false)
5769
+					{
5770
+						$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5771
+					}
4929 5772
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
4930
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5773
+					if ($preserveHTML==false)
5774
+					{
5775
+						$newBody = nl2br($newBody);
5776
+					}
5777
+					// we need this, as htmLawed removes \r\n
4931 5778
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
4932
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
5779
+					if ($preserveHTML==false)
5780
+					{
5781
+						$newBody = str_replace("<br />","\r\n",$newBody);
5782
+					}
4933 5783
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
4934 5784
 				}
4935 5785
 				$message .= $newBody;
@@ -4966,12 +5816,12 @@  discard block
 block discarded – undo
4966 5816
 				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
4967 5817
 				 )
4968 5818
 				)
4969
-			   )
4970
-			{
5819
+			   ) {
4971 5820
 				$s=explode(" ", $line);
4972 5821
 				$line = "";
4973 5822
 				$linecnt = 0;
4974
-				foreach ($s as &$v) {
5823
+				foreach ($s as &$v)
5824
+				{
4975 5825
 					$cnt = strlen($v);
4976 5826
 					// only break long words within the wordboundaries,
4977 5827
 					// but it may destroy links, so we check for href and dont do it if we find one
@@ -4981,14 +5831,20 @@  discard block
 block discarded – undo
4981 5831
 						$v=wordwrap($v, $allowedLength, $cut, true);
4982 5832
 					}
4983 5833
 					// the rest should be broken at the start of the new word that exceeds the limit
4984
-					if ($linecnt+$cnt > $allowedLength) {
5834
+					if ($linecnt+$cnt > $allowedLength)
5835
+					{
4985 5836
 						$v=$cut.$v;
4986 5837
 						#$linecnt = 0;
4987 5838
 						$linecnt =strlen($v)-strlen($cut);
4988
-					} else {
5839
+					}
5840
+					else
5841
+					{
4989 5842
 						$linecnt += $cnt;
4990 5843
 					}
4991
-					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
5844
+					if (strlen($v))
5845
+					{
5846
+						$line .= (strlen($line) ? " " : "").$v;
5847
+					}
4992 5848
 				}
4993 5849
 			}
4994 5850
 			$newStr .= $line . "\n";
@@ -5009,11 +5865,18 @@  discard block
 block discarded – undo
5009 5865
 	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5010 5866
 	{
5011 5867
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5012
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5868
+		if (empty($_folder))
5869
+		{
5870
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5871
+		}
5013 5872
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5014
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
5873
+		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false)
5874
+		{
5015 5875
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5016
-			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5876
+			if (!(is_object($_uid) || is_array($_uid)))
5877
+			{
5878
+				$_uid = (array)$_uid;
5879
+			}
5017 5880
 			$uidsToFetch->add($_uid);
5018 5881
 
5019 5882
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5023,8 +5886,10 @@  discard block
 block discarded – undo
5023 5886
 			$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5024 5887
 				'ids' => $uidsToFetch,
5025 5888
 			));
5026
-			if (is_object($headersNew)) {
5027
-				foreach($headersNew as &$_headerObject) {
5889
+			if (is_object($headersNew))
5890
+			{
5891
+				foreach($headersNew as &$_headerObject)
5892
+				{
5028 5893
 					$env = $_headerObject->getEnvelope();
5029 5894
 					//_debug_array($envFields->singleFields());
5030 5895
 					$singleFields = $envFields->singleFields();
@@ -5041,7 +5906,10 @@  discard block
 block discarded – undo
5041 5906
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5042 5907
 								$envelope[$v]=$env->$v->addresses;
5043 5908
 								$address = array();
5044
-								if (!is_array($envelope[$v])) break;
5909
+								if (!is_array($envelope[$v]))
5910
+								{
5911
+									break;
5912
+								}
5045 5913
 								foreach ($envelope[$v] as $k => $ad)
5046 5914
 								{
5047 5915
 									if (stripos($ad,'@')===false)
@@ -5078,7 +5946,9 @@  discard block
 block discarded – undo
5078 5946
 				}
5079 5947
 			}
5080 5948
 			return $envelope;
5081
-		} else {
5949
+		}
5950
+		else
5951
+		{
5082 5952
 
5083 5953
 			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5084 5954
 
@@ -5089,19 +5959,43 @@  discard block
 block discarded – undo
5089 5959
 				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5090 5960
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5091 5961
 			);
5092
-			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
5093
-			if (isset($headers['REFERENCES'])) $newData['REFERENCES'] = $headers['REFERENCES'];
5094
-			if (isset($headers['THREAD-TOPIC'])) $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
5095
-			if (isset($headers['THREAD-INDEX'])) $newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
5096
-			if (isset($headers['LIST-ID'])) $newData['LIST-ID'] = $headers['LIST-ID'];
5097
-			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
5962
+			if (isset($headers['IN-REPLY-TO']))
5963
+			{
5964
+				$newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
5965
+			}
5966
+			if (isset($headers['REFERENCES']))
5967
+			{
5968
+				$newData['REFERENCES'] = $headers['REFERENCES'];
5969
+			}
5970
+			if (isset($headers['THREAD-TOPIC']))
5971
+			{
5972
+				$newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
5973
+			}
5974
+			if (isset($headers['THREAD-INDEX']))
5975
+			{
5976
+				$newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
5977
+			}
5978
+			if (isset($headers['LIST-ID']))
5979
+			{
5980
+				$newData['LIST-ID'] = $headers['LIST-ID'];
5981
+			}
5982
+			if (isset($headers['SIZE']))
5983
+			{
5984
+				$newData['SIZE'] = $headers['SIZE'];
5985
+			}
5098 5986
 			//_debug_array($newData);
5099 5987
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5100
-			foreach($recepientList as $recepientType) {
5101
-				if(isset($headers[$recepientType])) {
5102
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
5988
+			foreach($recepientList as $recepientType)
5989
+			{
5990
+				if(isset($headers[$recepientType]))
5991
+				{
5992
+					if ($decode)
5993
+					{
5994
+						$headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
5995
+					}
5103 5996
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5104
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5997
+					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress)
5998
+					{
5105 5999
 						$addressData = array(
5106 6000
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5107 6001
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5109,17 +6003,25 @@  discard block
 block discarded – undo
5109 6003
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5110 6004
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5111 6005
 						);
5112
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
6006
+						if($addressData['PERSONAL_NAME'] != 'NIL')
6007
+						{
5113 6008
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5114
-						} else {
6009
+						}
6010
+						else
6011
+						{
5115 6012
 							$addressData['RFC822_EMAIL'] = 'NIL';
5116 6013
 						}
5117 6014
 						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5118 6015
 					}
5119
-				} else {
5120
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
6016
+				}
6017
+				else
6018
+				{
6019
+					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO')
6020
+					{
5121 6021
 						$newData[$recepientType] = $newData['FROM'];
5122
-					} else {
6022
+					}
6023
+					else
6024
+					{
5123 6025
 						$newData[$recepientType] = array();
5124 6026
 					}
5125 6027
 				}
@@ -5142,9 +6044,15 @@  discard block
 block discarded – undo
5142 6044
 	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5143 6045
 	{
5144 6046
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5145
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6047
+		if (empty($_folder))
6048
+		{
6049
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6050
+		}
5146 6051
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5147
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6052
+		if (!(is_object($_uid) || is_array($_uid)))
6053
+		{
6054
+			$_uid = (array)$_uid;
6055
+		}
5148 6056
 		$uidsToFetch->add($_uid);
5149 6057
 
5150 6058
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5162,7 +6070,8 @@  discard block
 block discarded – undo
5162 6070
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5163 6071
 			'ids' => $uidsToFetch,
5164 6072
 		));
5165
-		if (is_object($headersNew)) {
6073
+		if (is_object($headersNew))
6074
+		{
5166 6075
 			foreach($headersNew as $_fetchObject)
5167 6076
 			{
5168 6077
 				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
@@ -5184,11 +6093,17 @@  discard block
 block discarded – undo
5184 6093
 			}
5185 6094
 			if ($decode === 'object')
5186 6095
 			{
5187
-				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6096
+				if (is_object($headers))
6097
+				{
6098
+					$headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6099
+				}
5188 6100
 				return $headers;
5189 6101
 			}
5190 6102
 			$retValue = is_object($headers) ? $headers->toArray():array();
5191
-			if ($size) $retValue['size'] = $size;
6103
+			if ($size)
6104
+			{
6105
+				$retValue['size'] = $size;
6106
+			}
5192 6107
 		}
5193 6108
 		$retValue = array_change_key_case($retValue,CASE_UPPER);
5194 6109
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
@@ -5220,10 +6135,16 @@  discard block
 block discarded – undo
5220 6135
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5221 6136
 	{
5222 6137
 		static $rawHeaders;
5223
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6138
+		if (empty($_folder))
6139
+		{
6140
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6141
+		}
5224 6142
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5225 6143
 
5226
-		if (is_null($rawHeaders)||!is_array($rawHeaders)) $rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
6144
+		if (is_null($rawHeaders)||!is_array($rawHeaders))
6145
+		{
6146
+			$rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
6147
+		}
5227 6148
 		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5228 6149
 		{
5229 6150
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
@@ -5231,7 +6152,10 @@  discard block
 block discarded – undo
5231 6152
 		}
5232 6153
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5233 6154
 		$uid = $_uid;
5234
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6155
+		if (!(is_object($_uid) || is_array($_uid)))
6156
+		{
6157
+			$uid = (array)$_uid;
6158
+		}
5235 6159
 		$uidsToFetch->add($uid);
5236 6160
 
5237 6161
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5247,8 +6171,10 @@  discard block
 block discarded – undo
5247 6171
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5248 6172
 			'ids' => $uidsToFetch,
5249 6173
 		));
5250
-		if (is_object($headersNew)) {
5251
-			foreach($headersNew as &$_headerObject) {
6174
+		if (is_object($headersNew))
6175
+		{
6176
+			foreach($headersNew as &$_headerObject)
6177
+			{
5252 6178
 				$retValue = $_headerObject->getHeaderText();
5253 6179
 				if ($_partID != '')
5254 6180
 				{
@@ -5276,22 +6202,33 @@  discard block
 block discarded – undo
5276 6202
 	static function &getStyles($_bodyParts)
5277 6203
 	{
5278 6204
 		$style = '';
5279
-		if (empty($_bodyParts)) return "";
5280
-		foreach((array)$_bodyParts as $singleBodyPart) {
5281
-			if (!isset($singleBodyPart['body'])) {
6205
+		if (empty($_bodyParts))
6206
+		{
6207
+			return "";
6208
+		}
6209
+		foreach((array)$_bodyParts as $singleBodyPart)
6210
+		{
6211
+			if (!isset($singleBodyPart['body']))
6212
+			{
5282 6213
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5283 6214
 				$style .= $singleBodyPart['body'];
5284 6215
 				continue;
5285 6216
 			}
5286 6217
 
5287
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6218
+			if ($singleBodyPart['charSet']===false)
6219
+			{
6220
+				$singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6221
+			}
5288 6222
 			$singleBodyPart['body'] = Translation::convert(
5289 6223
 				$singleBodyPart['body'],
5290 6224
 				strtolower($singleBodyPart['charSet'])
5291 6225
 			);
5292 6226
 			$ct = 0;
5293 6227
 			$newStyle=array();
5294
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6228
+			if (stripos($singleBodyPart['body'],'<style')!==false)
6229
+			{
6230
+				$ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6231
+			}
5295 6232
 			if ($ct>0)
5296 6233
 			{
5297 6234
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
@@ -5323,7 +6260,11 @@  discard block
 block discarded – undo
5323 6260
 		// CSS Security
5324 6261
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5325 6262
 		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5326
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
6263
+		if (stripos($css,'script')!==false)
6264
+		{
6265
+			Mail\Html::replaceTagsCompletley($css,'script');
6266
+		}
6267
+		// Strip out script that may be included
5327 6268
 		// we need this, as styledefinitions are enclosed with curly brackets; and template stuff tries to replace everything between curly brackets that is having no horizontal whitespace
5328 6269
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5329 6270
 		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
@@ -5344,8 +6285,14 @@  discard block
 block discarded – undo
5344 6285
 	{
5345 6286
 		//TODO: caching einbauen static!
5346 6287
 		static $rawBody;
5347
-		if (is_null($rawBody)) $rawBody = array();
5348
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6288
+		if (is_null($rawBody))
6289
+		{
6290
+			$rawBody = array();
6291
+		}
6292
+		if (empty($_folder))
6293
+		{
6294
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6295
+		}
5349 6296
 		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5350 6297
 		{
5351 6298
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
@@ -5354,7 +6301,10 @@  discard block
 block discarded – undo
5354 6301
 
5355 6302
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5356 6303
 		$uid = $_uid;
5357
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6304
+		if (!(is_object($_uid) || is_array($_uid)))
6305
+		{
6306
+			$uid = (array)$_uid;
6307
+		}
5358 6308
 		$uidsToFetch->add($uid);
5359 6309
 
5360 6310
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5367,8 +6317,10 @@  discard block
 block discarded – undo
5367 6317
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5368 6318
 			'ids' => $uidsToFetch,
5369 6319
 		));
5370
-		if (is_object($headersNew)) {
5371
-			foreach($headersNew as &$_headerObject) {
6320
+		if (is_object($headersNew))
6321
+		{
6322
+			foreach($headersNew as &$_headerObject)
6323
+			{
5372 6324
 				$body = $_headerObject->getFullMsg();
5373 6325
 				if ($_partID != '')
5374 6326
 				{
@@ -5401,14 +6353,20 @@  discard block
 block discarded – undo
5401 6353
 	 */
5402 6354
 	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5403 6355
 	{
5404
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6356
+		if (self::$debug)
6357
+		{
6358
+			error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6359
+		}
5405 6360
 
5406 6361
 		if (empty($_folder))
5407 6362
 		{
5408 6363
 			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5409 6364
 		}
5410 6365
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5411
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6366
+		if (!(is_object($_uid) || is_array($_uid)))
6367
+		{
6368
+			$_uid = (array)$_uid;
6369
+		}
5412 6370
 		$uidsToFetch->add($_uid);
5413 6371
 		try
5414 6372
 		{
@@ -5417,7 +6375,10 @@  discard block
 block discarded – undo
5417 6375
 	//		$fquery->envelope();
5418 6376
 	//		$fquery->size();
5419 6377
 			$_fquery->structure();
5420
-			if ($_partID) $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6378
+			if ($_partID)
6379
+			{
6380
+				$_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6381
+			}
5421 6382
 
5422 6383
 			$mail = $this->icServer->fetch($_folder, $_fquery, array(
5423 6384
 				'ids' => $uidsToFetch,
@@ -5448,16 +6409,28 @@  discard block
 block discarded – undo
5448 6409
 	 */
5449 6410
 	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5450 6411
 	{
5451
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5452
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6412
+		if (self::$debug)
6413
+		{
6414
+			error_log( __METHOD__.":$_uid, $_partID");
6415
+		}
6416
+		if (empty($_folder))
6417
+		{
6418
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6419
+		}
5453 6420
 		$attachments = array();
5454 6421
 		if (!isset($_structure))
5455 6422
 		{
5456 6423
 			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5457 6424
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5458 6425
 		}
5459
-		if (!$_structure || !$_structure->contentTypeMap()) return array();
5460
-		if (!empty($_partID)) $_structure = $_structure->getPart($_partID);
6426
+		if (!$_structure || !$_structure->contentTypeMap())
6427
+		{
6428
+			return array();
6429
+		}
6430
+		if (!empty($_partID))
6431
+		{
6432
+			$_structure = $_structure->getPart($_partID);
6433
+		}
5461 6434
 		$skipParts = array();
5462 6435
 		$tnefParts = array();
5463 6436
 		$skip = 0;
@@ -5486,7 +6459,13 @@  discard block
 block discarded – undo
5486 6459
 			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5487 6460
 			{
5488 6461
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5489
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
6462
+				foreach($part->contentTypeMap() as $sub_id => $sub_type)
6463
+				{
6464
+if ($sub_id != $mime_id)
6465
+				{
6466
+					$skipParts[$sub_id] = $sub_type;
6467
+				}
6468
+				}
5490 6469
 			}
5491 6470
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5492 6471
 			{
@@ -5497,7 +6476,10 @@  discard block
 block discarded – undo
5497 6476
 				$partDisposition='attachment';
5498 6477
 			}
5499 6478
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5500
-			if (array_key_exists($mime_id,$skipParts)) continue;
6479
+			if (array_key_exists($mime_id,$skipParts))
6480
+			{
6481
+				continue;
6482
+			}
5501 6483
 
5502 6484
 			if ($partDisposition == 'attachment' ||
5503 6485
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
@@ -5508,23 +6490,41 @@  discard block
 block discarded – undo
5508 6490
 			{
5509 6491
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5510 6492
 				// we attempt to fetch "ourselves"
5511
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
6493
+				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message')
6494
+				{
6495
+					continue;
6496
+				}
5512 6497
 				$attachment = $part->getAllDispositionParameters();
5513 6498
 				$attachment['disposition'] = $part->getDisposition();
5514 6499
 				$attachment['mimeType'] = $mime_type;
5515 6500
 				$attachment['uid'] = $_uid;
5516 6501
 				$attachment['partID'] = $mime_id;
5517
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6502
+				if (!isset($attachment['name'])||empty($attachment['name']))
6503
+				{
6504
+					$attachment['name'] = $part->getName();
6505
+				}
5518 6506
 				if ($fetchTextCalendar)
5519 6507
 				{
5520 6508
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
5521 6509
 					$method = $part->getContentTypeParameter('method');
5522
-					if ($method) $attachment['method'] = $method;
5523
-					if (!isset($attachment['name'])) $attachment['name'] = 'event.ics';
6510
+					if ($method)
6511
+					{
6512
+						$attachment['method'] = $method;
6513
+					}
6514
+					if (!isset($attachment['name']))
6515
+					{
6516
+						$attachment['name'] = 'event.ics';
6517
+					}
5524 6518
 				}
5525 6519
 				$attachment['size'] = $part->getBytes();
5526
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5527
-				if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
6520
+				if (($cid = $part->getContentId()))
6521
+				{
6522
+					$attachment['cid'] = $cid;
6523
+				}
6524
+				if (empty($attachment['name']))
6525
+				{
6526
+					$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
6527
+				}
5528 6528
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5529 6529
 				//typical winmail.dat attachment is
5530 6530
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
@@ -5560,14 +6560,26 @@  discard block
 block discarded – undo
5560 6560
 						$attachment['uid'] = $tnp['uid'];
5561 6561
 						$attachment['partID'] = $tnp['partID'];
5562 6562
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5563
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6563
+						if (!isset($attachment['name'])||empty($attachment['name']))
6564
+						{
6565
+							$attachment['name'] = $part->getName();
6566
+						}
5564 6567
 						$attachment['size'] = $part->getBytes();
5565
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5566
-						if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6568
+						if (($cid = $part->getContentId()))
6569
+						{
6570
+							$attachment['cid'] = $cid;
6571
+						}
6572
+						if (empty($attachment['name']))
6573
+						{
6574
+							$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6575
+						}
5567 6576
 						$attachments[] = $attachment;
5568 6577
 					}
5569 6578
 				}
5570
-				if ($tnefResolved===false) $attachments[]=$tnp;
6579
+				if ($tnefResolved===false)
6580
+				{
6581
+					$attachments[]=$tnp;
6582
+				}
5571 6583
 			}
5572 6584
 		}
5573 6585
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5671,8 +6683,14 @@  discard block
 block discarded – undo
5671 6683
 
5672 6684
 				$attachment = $part->getAllDispositionParameters();
5673 6685
 				$attachment['mimeType'] = $part->getType();
5674
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5675
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
6686
+				if (!isset($attachment['filename'])||empty($attachment['filename']))
6687
+				{
6688
+					$attachment['filename'] = $part->getName();
6689
+				}
6690
+				if (($cid = $part->getContentId()))
6691
+				{
6692
+					$attachment['cid'] = $cid;
6693
+				}
5676 6694
 				if (empty($attachment['filename']))
5677 6695
 				{
5678 6696
 					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
@@ -5684,7 +6702,10 @@  discard block
 block discarded – undo
5684 6702
 				$attachments[$_uid.'@'.$_partID.'@'.$mime_id] = $attachment;
5685 6703
 			}
5686 6704
 		}
5687
-		if (!is_array($attachments)) return false;
6705
+		if (!is_array($attachments))
6706
+		{
6707
+			return false;
6708
+		}
5688 6709
 		return $attachments;
5689 6710
 	}
5690 6711
 
@@ -5703,10 +6724,16 @@  discard block
 block discarded – undo
5703 6724
 	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5704 6725
 	{
5705 6726
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5706
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6727
+		if (!isset($_folder))
6728
+		{
6729
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6730
+		}
5707 6731
 
5708 6732
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5709
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6733
+		if (!(is_object($_uid) || is_array($_uid)))
6734
+		{
6735
+			$_uid = (array)$_uid;
6736
+		}
5710 6737
 		$uidsToFetch->add($_uid);
5711 6738
 
5712 6739
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5715,8 +6742,10 @@  discard block
 block discarded – undo
5715 6742
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5716 6743
 			'ids' => $uidsToFetch,
5717 6744
 		));
5718
-		if (is_object($headersNew)) {
5719
-			foreach($headersNew as $id=>$_headerObject) {
6745
+		if (is_object($headersNew))
6746
+		{
6747
+			foreach($headersNew as $id=>$_headerObject)
6748
+			{
5720 6749
 				$body = $_headerObject->getFullMsg();
5721 6750
 				if ($_partID != '')
5722 6751
 				{
@@ -5730,7 +6759,10 @@  discard block
 block discarded – undo
5730 6759
 					}
5731 6760
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5732 6761
 					// itself is only triggered to fetch attachments
5733
-					if (empty($partDisposition)) $partDisposition='attachment';
6762
+					if (empty($partDisposition))
6763
+					{
6764
+						$partDisposition='attachment';
6765
+					}
5734 6766
 					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5735 6767
 					{
5736 6768
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
@@ -5739,13 +6771,19 @@  discard block
 block discarded – undo
5739 6771
 						$charset = $part->getContentTypeParameter('charset');
5740 6772
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5741 6773
 						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5742
-						if ($_returnPart) return $part;
6774
+						if ($_returnPart)
6775
+						{
6776
+							return $part;
6777
+						}
5743 6778
 					}
5744 6779
 				}
5745 6780
 			}
5746 6781
 		}
5747 6782
 		$ext = MimeMagic::mime2ext($structure_mime);
5748
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
6783
+		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false)
6784
+		{
6785
+			$filename = trim($filename).'.'.$ext;
6786
+		}
5749 6787
 		if (!$part)
5750 6788
 		{
5751 6789
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5761,7 +6799,10 @@  discard block
 block discarded – undo
5761 6799
 		);
5762 6800
 
5763 6801
 		// try guessing the mimetype, if we get the application/octet-stream
5764
-		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6802
+		if (strtolower($attachmentData['type']) == 'application/octet-stream')
6803
+		{
6804
+			$attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6805
+		}
5765 6806
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5766 6807
 		if ( $filename == 'winmail.dat' && $_winmail_nr)
5767 6808
 		{
@@ -5784,9 +6825,18 @@  discard block
 block discarded – undo
5784 6825
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5785 6826
 					{
5786 6827
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5787
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5788
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5789
-						if (empty($attachment['filename'])) $attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6828
+						if (!isset($attachment['filename'])||empty($attachment['filename']))
6829
+						{
6830
+							$attachment['filename'] = $part->getName();
6831
+						}
6832
+						if (($cid = $part->getContentId()))
6833
+						{
6834
+							$attachment['cid'] = $cid;
6835
+						}
6836
+						if (empty($attachment['filename']))
6837
+						{
6838
+							$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6839
+						}
5790 6840
 						$wmattach = $attachment;
5791 6841
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5792 6842
 
@@ -5796,7 +6846,10 @@  discard block
 block discarded – undo
5796 6846
 			if ($tnefResolved)
5797 6847
 			{
5798 6848
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5799
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6849
+				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false)
6850
+				{
6851
+					$wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6852
+				}
5800 6853
 				$attachmentData = array(
5801 6854
 					'type'       => $wmattach['mimeType'],
5802 6855
 					'filename'   => $wmattach['filename'],
@@ -5826,7 +6879,10 @@  discard block
 block discarded – undo
5826 6879
 		static $uid=null, $part=null, $structure=null;
5827 6880
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5828 6881
 
5829
-		if(empty($_cid)) return false;
6882
+		if(empty($_cid))
6883
+		{
6884
+			return false;
6885
+		}
5830 6886
 
5831 6887
 		if ($_uid != $uid || $_part != $part)
5832 6888
 		{
@@ -5851,13 +6907,19 @@  discard block
 block discarded – undo
5851 6907
 					$attachment = $part;
5852 6908
 				}
5853 6909
 				// everything else we only consider after we checked all
5854
-				if (!isset($attachment)) $attachment = $part;
6910
+				if (!isset($attachment))
6911
+				{
6912
+					$attachment = $part;
6913
+				}
5855 6914
 				// do we want content fetched, can be done later, if not needed
5856 6915
 				if (isset($_stream))
5857 6916
 				{
5858 6917
 					$this->fetchPartContents($_uid, $attachment, $_stream);
5859 6918
 				}
5860
-				if (isset($attachment)) break;
6919
+				if (isset($attachment))
6920
+				{
6921
+					break;
6922
+				}
5861 6923
 			}
5862 6924
 		}
5863 6925
 		// set name as filename, if not set
@@ -5888,10 +6950,17 @@  discard block
 block discarded – undo
5888 6950
 	 */
5889 6951
 	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
5890 6952
 	{
5891
-		if (is_null($part)) return null;//new Horde_Mime_Part;
6953
+		if (is_null($part))
6954
+		{
6955
+			return null;
6956
+		}
6957
+		//new Horde_Mime_Part;
5892 6958
 		$encoding = null;
5893 6959
 		$fetchAsBinary = true;
5894
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
6960
+		if ($_mimetype && strtolower($_mimetype)=='message/rfc822')
6961
+		{
6962
+			$fetchAsBinary = false;
6963
+		}
5895 6964
 		// we need to set content on structure to decode transfer encoding
5896 6965
 		$part->setContents(
5897 6966
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
@@ -5928,7 +6997,10 @@  discard block
 block discarded – undo
5928 6997
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
5929 6998
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
5930 6999
 		// for flags at all)
5931
-		if (empty($_flags)) $_flags = '\\Recent';
7000
+		if (empty($_flags))
7001
+		{
7002
+			$_flags = '\\Recent';
7003
+		}
5932 7004
 		//if (!is_array($_flags) && stripos($_flags,',')!==false) $_flags=explode(',',$_flags);
5933 7005
 		//if (!is_array($_flags)) $_flags = (array) $_flags;
5934 7006
 		try
@@ -5945,18 +7017,27 @@  discard block
 block discarded – undo
5945 7017
 		}
5946 7018
 		catch (\Exception $e)
5947 7019
 		{
5948
-			if (self::$debug) error_log("Could not append Message: ".$e->getMessage());
7020
+			if (self::$debug)
7021
+			{
7022
+				error_log("Could not append Message: ".$e->getMessage());
7023
+			}
5949 7024
 			throw new Exception\WrongUserinput(lang("Could not append Message:").' '.$e->getMessage().': '.$e->details);
5950 7025
 			//return false;
5951 7026
 		}
5952 7027
 		//error_log(__METHOD__.' ('.__LINE__.') '.' appended UID:'.$messageid);
5953 7028
 		//$messageid = true; // for debug reasons only
5954
-		if ($messageid === true || empty($messageid)) // try to figure out the message uid
7029
+		if ($messageid === true || empty($messageid))
7030
+		{
7031
+			// try to figure out the message uid
5955 7032
 		{
5956 7033
 			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
7034
+		}
5957 7035
 			if ($list)
5958 7036
 			{
5959
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7037
+				if (self::$debug)
7038
+				{
7039
+					error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7040
+				}
5960 7041
 				$messageid = $list['header'][0]['uid'];
5961 7042
 			}
5962 7043
 		}
@@ -5997,7 +7078,10 @@  discard block
 block discarded – undo
5997 7078
 	{
5998 7079
 			//echo __METHOD__." called for $uid,$partid <br>";
5999 7080
 			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
6000
-			if (empty($headers)) return false;
7081
+			if (empty($headers))
7082
+			{
7083
+				return false;
7084
+			}
6001 7085
 			// dont force retrieval of the textpart, let mailClass preferences decide
6002 7086
 			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6003 7087
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
@@ -6015,15 +7099,30 @@  discard block
 block discarded – undo
6015 7099
 			//error_log(array2string($bodyParts));
6016 7100
 			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6017 7101
 
6018
-			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6019
-			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
6020
-			elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER'];
6021
-			if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC'];
7102
+			if ($mailClass->isSentFolder($mailbox))
7103
+			{
7104
+				$mailaddress = $headers['TO'];
7105
+			}
7106
+			elseif (isset($headers['FROM']))
7107
+			{
7108
+				$mailaddress = $headers['FROM'];
7109
+			}
7110
+			elseif (isset($headers['SENDER']))
7111
+			{
7112
+				$mailaddress = $headers['SENDER'];
7113
+			}
7114
+			if (isset($headers['CC']))
7115
+			{
7116
+				$mailaddress .= ','.$headers['CC'];
7117
+			}
6022 7118
 			//_debug_array(array($headers,$mailaddress));
6023 7119
 			$subject = $headers['SUBJECT'];
6024 7120
 
6025 7121
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6026
-			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
7122
+			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain')
7123
+			{
7124
+				$message = '<pre>'.$message.'</pre>';
7125
+			}
6027 7126
 			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6028 7127
 			$message = $headdata.$message;
6029 7128
 			//echo __METHOD__.'<br>';
@@ -6074,7 +7173,8 @@  discard block
 block discarded – undo
6074 7173
 							$attachments[$num]['attachment'] = $c->getContents();
6075 7174
 						}
6076 7175
 						// no attempt to convert, if we dont know about the charset
6077
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
7176
+						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset']))
7177
+						{
6078 7178
 							// we do not try guessing the charset, if it is not set
6079 7179
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6080 7180
 							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
@@ -6095,7 +7195,10 @@  discard block
 block discarded – undo
6095 7195
 						unset($attachments[$num]['attachment']);
6096 7196
 					}
6097 7197
 				}
6098
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
7198
+				if (is_array($attachedMessages))
7199
+				{
7200
+					$attachments = array_merge($attachments,$attachedMessages);
7201
+				}
6099 7202
 			}
6100 7203
 			return array(
6101 7204
 					'mailaddress'=>$mailaddress,
@@ -6117,10 +7220,17 @@  discard block
 block discarded – undo
6117 7220
 	{
6118 7221
 		$c = 0;
6119 7222
 		// use the standardIdentity
6120
-		foreach($_identities as $key => $acc) {
6121
-			if ($c==0) $identity = $acc;
7223
+		foreach($_identities as $key => $acc)
7224
+		{
7225
+			if ($c==0)
7226
+			{
7227
+				$identity = $acc;
7228
+			}
6122 7229
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6123
-			if ($key==$_profile_id) $identity = $acc;
7230
+			if ($key==$_profile_id)
7231
+			{
7232
+				$identity = $acc;
7233
+			}
6124 7234
 			$c++;
6125 7235
 		}
6126 7236
 		return $identity;
@@ -6136,20 +7246,53 @@  discard block
 block discarded – undo
6136 7246
 	{
6137 7247
 		$headdata = null;
6138 7248
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6139
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6140
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6141
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6142
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6143
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6144
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6145
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6146
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6147
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7249
+		if ($header['SUBJECT'])
7250
+		{
7251
+			$headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
7252
+		}
7253
+		if ($header['FROM'])
7254
+		{
7255
+			$headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
7256
+		}
7257
+		if ($header['SENDER'])
7258
+		{
7259
+			$headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
7260
+		}
7261
+		if ($header['TO'])
7262
+		{
7263
+			$headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
7264
+		}
7265
+		if ($header['CC'])
7266
+		{
7267
+			$headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
7268
+		}
7269
+		if ($header['BCC'])
7270
+		{
7271
+			$headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
7272
+		}
7273
+		if ($header['DATE'])
7274
+		{
7275
+			$headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
7276
+		}
7277
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal')
7278
+		{
7279
+			$headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
7280
+		}
7281
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal')
7282
+		{
7283
+			$headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7284
+		}
6148 7285
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6149 7286
 		if (!empty($headdata))
6150 7287
 		{
6151
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6152
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7288
+			if (!empty($headline) && $headline != 'SUPPRESS')
7289
+			{
7290
+				$headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
7291
+			}
7292
+			if (empty($headline))
7293
+			{
7294
+				$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7295
+			}
6153 7296
 			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6154 7297
 		}
6155 7298
 		else
@@ -6183,12 +7326,15 @@  discard block
 block discarded – undo
6183 7326
 		$returnAddr ='';
6184 7327
 		if (is_array($rfcAddressArray))
6185 7328
 		{
6186
-			foreach((array)$rfcAddressArray as $addressData) {
7329
+			foreach((array)$rfcAddressArray as $addressData)
7330
+			{
6187 7331
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6188
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
7332
+				if($addressData['MAILBOX_NAME'] == 'NIL')
7333
+				{
6189 7334
 					continue;
6190 7335
 				}
6191
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
7336
+				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients')
7337
+				{
6192 7338
 					continue;
6193 7339
 				}
6194 7340
 				if ($addressData['RFC822_EMAIL'])
@@ -6202,7 +7348,10 @@  discard block
 block discarded – undo
6202 7348
 				}
6203 7349
 				$addressObject = $addressObjectA[0];
6204 7350
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressObject));
6205
-				if (!$addressObject->valid) continue;
7351
+				if (!$addressObject->valid)
7352
+				{
7353
+					continue;
7354
+				}
6206 7355
 				//$mb =(string)$addressObject->mailbox;
6207 7356
 				//$h = (string)$addressObject->host;
6208 7357
 				//$p = (string)$addressObject->personal;
@@ -6219,7 +7368,10 @@  discard block
 block discarded – undo
6219 7368
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6220 7369
 			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6221 7370
 			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6222
-			if (is_string($rfcAddressArray)) return $rfcAddressArray;
7371
+			if (is_string($rfcAddressArray))
7372
+			{
7373
+				return $rfcAddressArray;
7374
+			}
6223 7375
 		}
6224 7376
 		return $returnAddr;
6225 7377
 	}
@@ -6236,10 +7388,19 @@  discard block
 block discarded – undo
6236 7388
 	{
6237 7389
 		$mergeobj = new Contacts\Merge();
6238 7390
 
6239
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7391
+		if (empty($mimetype))
7392
+		{
7393
+			$mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7394
+		}
6240 7395
 		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6241
-		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6242
-		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7396
+		if (empty($rv) && !empty($content) && !empty($err))
7397
+		{
7398
+			$rv = $content;
7399
+		}
7400
+		if (!empty($err) && !empty($content) && !empty($ids))
7401
+		{
7402
+			error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7403
+		}
6243 7404
 		return $rv;
6244 7405
 	}
6245 7406
 
@@ -6276,13 +7437,15 @@  discard block
 block discarded – undo
6276 7437
 			settype($bytes, 'integer');
6277 7438
 			$bytes /= 10;
6278 7439
 		}
6279
-		else
6280
-			settype($bytes, 'integer');
7440
+		else {
7441
+					settype($bytes, 'integer');
7442
+		}
6281 7443
 
6282 7444
 		return $bytes . ' ' . $type ;
6283 7445
 	}
6284 7446
 
6285
-	static function detect_qp(&$sting) {
7447
+	static function detect_qp(&$sting)
7448
+	{
6286 7449
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6287 7450
 		return preg_match("$needle",$string);
6288 7451
 	}
@@ -6299,9 +7462,15 @@  discard block
 block discarded – undo
6299 7462
 	 */
6300 7463
 	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6301 7464
 	{
6302
-		if (is_null($_endtime)) $_endtime = microtime(true);
7465
+		if (is_null($_endtime))
7466
+		{
7467
+			$_endtime = microtime(true);
7468
+		}
6303 7469
 		$usagetime = microtime(true) - $_starttime;
6304
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7470
+		if (self::$debugTimes)
7471
+		{
7472
+			error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7473
+		}
6305 7474
 	}
6306 7475
 
6307 7476
 	/**
@@ -6316,7 +7485,10 @@  discard block
 block discarded – undo
6316 7485
 	 */
6317 7486
 	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6318 7487
 	{
6319
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
7488
+		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data')
7489
+		{
7490
+			return $_formData['file'];
7491
+		}
6320 7492
 
6321 7493
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6322 7494
 		$importfailed = $tmpFileName = false;
@@ -6365,8 +7537,15 @@  discard block
 block discarded – undo
6365 7537
 			{
6366 7538
 				$buff = explode('.',$_formData['name']);
6367 7539
 				$suffix = '';
6368
-				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6369
-				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
7540
+				if (is_array($buff))
7541
+				{
7542
+					$suffix = array_pop($buff);
7543
+				}
7544
+				// take the last extension to check with ext2mime
7545
+				if (!empty($suffix))
7546
+				{
7547
+					$sfxMimeType = MimeMagic::ext2mime($suffix);
7548
+				}
6370 7549
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6371 7550
 					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6372 7551
 				{
@@ -6414,7 +7593,9 @@  discard block
 block discarded – undo
6414 7593
 			{
6415 7594
 				rename($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);
6416 7595
 			}
6417
-		} else {
7596
+		}
7597
+		else
7598
+		{
6418 7599
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6419 7600
 			$importfailed = true;
6420 7601
 			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
@@ -6460,21 +7641,32 @@  discard block
 block discarded – undo
6460 7641
 				if (substr($url, 0, 5) !== 'data:')
6461 7642
 				{
6462 7643
 					$filename = basename($url);
6463
-					if (($directory = dirname($url)) == '.') $directory = '';
7644
+					if (($directory = dirname($url)) == '.')
7645
+					{
7646
+						$directory = '';
7647
+					}
6464 7648
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6465 7649
 					$mimeType  = MimeMagic::ext2mime($ext);
6466
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
7650
+					if ( strlen($directory) > 1 && substr($directory,-1) != '/')
7651
+					{
7652
+$directory .= '/'; }
6467 7653
 					$myUrl = $directory.$filename;
6468
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
7654
+					if ($myUrl[0]=='/')
7655
+					{
7656
+						// local path -> we only allow path's that are available via http/https (or vfs)
6469 7657
 					{
6470 7658
 						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6471 7659
 					}
7660
+					}
6472 7661
 					// use vfs instead of url containing webdav.php
6473 7662
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6474 7663
 					// webdav.php urls as vfs
6475
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
7664
+					if (strpos($myUrl,'/webdav.php') !== false)
7665
+					{
7666
+						// we have a webdav link, so we build a vfs/sqlfs link of it.
6476 7667
 					{
6477 7668
 						Vfs::load_wrapper('vfs');
7669
+					}
6478 7670
 						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6479 7671
 						$basedir = 'vfs://default';
6480 7672
 						$needTempFile = false;
@@ -6503,8 +7695,13 @@  discard block
 block discarded – undo
6503 7695
 						}
6504 7696
 					}
6505 7697
 
6506
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6507
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
7698
+					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/')
7699
+					{
7700
+$basedir .= '/'; }
7701
+					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http")
7702
+					{
7703
+						$data = file_get_contents($basedir.urldecode($myUrl));
7704
+					}
6508 7705
 				}
6509 7706
 				if (substr($url,0,strlen('data:'))=='data:')
6510 7707
 				{
@@ -6605,7 +7802,10 @@  discard block
 block discarded – undo
6605 7802
 				$_folder = $this->getSentFolder();
6606 7803
 			}
6607 7804
 			$delimiter = $this->getHierarchyDelimiter();
6608
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
7805
+			if($_folder=='INBOX'.$delimiter)
7806
+			{
7807
+				$_folder='INBOX';
7808
+			}
6609 7809
 			if ($importfailed === false)
6610 7810
 			{
6611 7811
 				$Subject = $mailObject->getHeader('Subject');
@@ -6634,7 +7834,9 @@  discard block
 block discarded – undo
6634 7834
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val);
6635 7835
 					if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/
6636 7836
 						count($SendAndMergeTocontacts) > 1 && $val &&
6637
-						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge
7837
+						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)))
7838
+					{
7839
+						// do the merge
6638 7840
 					{
6639 7841
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6640 7842
 
@@ -6643,6 +7845,7 @@  discard block
 block discarded – undo
6643 7845
 						{
6644 7846
 							//error_log('ID ' . $val . ' ' .$type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset));
6645 7847
 							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
7848
+					}
6646 7849
 							$mailObject->addAddress($merged,'',$type);
6647 7850
 							if($type == 'to')
6648 7851
 							{
@@ -6674,9 +7877,15 @@  discard block
 block discarded – undo
6674 7877
 						$mailObject->clearCustomHeaders();
6675 7878
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6676 7879
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6677
-						if($text_body) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7880
+						if($text_body)
7881
+						{
7882
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7883
+						}
6678 7884
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6679
-						if($html_body) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7885
+						if($html_body)
7886
+						{
7887
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7888
+						}
6680 7889
 
6681 7890
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6682 7891
 						// set a higher timeout for big messages
@@ -6691,9 +7900,12 @@  discard block
 block discarded – undo
6691 7900
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
6692 7901
 						}
6693 7902
 					}
6694
-					elseif (!$k)	// 1. entry, further entries will fail for apps other then addressbook
7903
+					elseif (!$k)
7904
+					{
7905
+						// 1. entry, further entries will fail for apps other then addressbook
6695 7906
 					{
6696 7907
 						$openAsDraft = true;
7908
+					}
6697 7909
 						$mailObject->removeHeader('Message-ID');
6698 7910
 						$mailObject->removeHeader('Date');
6699 7911
 						$mailObject->clearCustomHeaders();
@@ -6708,9 +7920,12 @@  discard block
 block discarded – undo
6708 7920
 
6709 7921
 						// No addresses from placeholders?  Treat it as just a contact ID
6710 7922
 						if (count($mailObject->getAddresses('to',true)) == 0 &&
6711
-							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
7923
+							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))
7924
+						{
7925
+							// do the merge
6712 7926
 						{
6713 7927
 							$contact = $bo_merge->contacts->read($val);
7928
+						}
6714 7929
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6715 7930
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6716 7931
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
@@ -6721,9 +7936,15 @@  discard block
 block discarded – undo
6721 7936
 						}
6722 7937
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6723 7938
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6724
-						if (!empty($Body)) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7939
+						if (!empty($Body))
7940
+						{
7941
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7942
+						}
6725 7943
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6726
-						if (!empty($AltBody)) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7944
+						if (!empty($AltBody))
7945
+						{
7946
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7947
+						}
6727 7948
 						$_folder = $this->getDraftFolder();
6728 7949
 					}
6729 7950
 					if ($sendOK || $openAsDraft)
@@ -6731,11 +7952,15 @@  discard block
 block discarded – undo
6731 7952
 						if ($this->folderExists($_folder,true))
6732 7953
 						{
6733 7954
 						    if($this->isSentFolder($_folder))
6734
-							{
7955
+						    {
6735 7956
 						        $flags = '\\Seen';
6736
-						    } elseif($this->isDraftFolder($_folder)) {
7957
+						    }
7958
+						    elseif($this->isDraftFolder($_folder))
7959
+						    {
6737 7960
 						        $flags = '\\Draft';
6738
-						    } else {
7961
+						    }
7962
+						    else
7963
+						    {
6739 7964
 						        $flags = '';
6740 7965
 						    }
6741 7966
 							$savefailed = false;
@@ -6769,7 +7994,10 @@  discard block
 block discarded – undo
6769 7994
 						}
6770 7995
 						else
6771 7996
 						{
6772
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
7997
+							if (!$openComposeWindow)
7998
+							{
7999
+								$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8000
+							}
6773 8001
 						}
6774 8002
 					}
6775 8003
 					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
@@ -6817,7 +8045,10 @@  discard block
 block discarded – undo
6817 8045
 				$tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($tmpFileName);
6818 8046
 				break;
6819 8047
 		}
6820
-		if (!isset($message)) $message = fopen($tmpFileName, 'r');
8048
+		if (!isset($message))
8049
+		{
8050
+			$message = fopen($tmpFileName, 'r');
8051
+		}
6821 8052
 
6822 8053
 		if (!$message)
6823 8054
 		{
@@ -6848,7 +8079,10 @@  discard block
 block discarded – undo
6848 8079
 				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6849 8080
 
6850 8081
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6851
-			if ($length===false) $length = strlen($start);
8082
+			if ($length===false)
8083
+			{
8084
+				$length = strlen($start);
8085
+			}
6852 8086
 			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6853 8087
 
6854 8088
 			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
@@ -6877,7 +8111,10 @@  discard block
 block discarded – undo
6877 8111
 		}
6878 8112
 		else
6879 8113
 		{
6880
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
8114
+			if (($type = gettype($message)) == 'object')
8115
+			{
8116
+				$type = get_class ($message);
8117
+			}
6881 8118
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
6882 8119
 		}
6883 8120
 	}
@@ -6901,7 +8138,9 @@  discard block
 block discarded – undo
6901 8138
 			$matches = array();
6902 8139
 			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
6903 8140
 			//error_log(__METHOD__.__LINE__.array2string($matches));
6904
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
8141
+			foreach ($matches[0] as &$match)
8142
+			{
8143
+$match = trim($match,', ');}
6905 8144
 			$addresses = implode(',',$matches[0]);
6906 8145
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
6907 8146
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
@@ -6932,7 +8171,10 @@  discard block
 block discarded – undo
6932 8171
 			}
6933 8172
 			else
6934 8173
 			{
6935
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
8174
+				if ($previousFailed && $remember)
8175
+				{
8176
+					$adr->personal = $remember. ' ' . $adr->personal;
8177
+				}
6936 8178
 				$remember = '';
6937 8179
 				$previousFailed=false;
6938 8180
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
@@ -6954,7 +8196,10 @@  discard block
 block discarded – undo
6954 8196
 	{
6955 8197
 		$acc = Mail\Account::read($this->profileID);
6956 8198
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
6957
-		if (self::$debug) error_log(__METHOD__.__LINE__.array2string($identity));
8199
+		if (self::$debug)
8200
+		{
8201
+			error_log(__METHOD__.__LINE__.array2string($identity));
8202
+		}
6958 8203
 		$headers = $this->getMessageHeader($uid, '', 'object', true, $_folder);
6959 8204
 
6960 8205
 		$mdn = new Horde_Mime_Mdn($headers);
Please login to merge, or discard this patch.
api/src/Mail/Account.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 	 * @param boolean $replace_placeholders =false should placeholders like {{n_fn}} be replaced
487 487
 	 * @param string $field ='name' what to return as value: "ident_(realname|org|email|signature)" or default "name"=result from identity_name
488 488
 	 * @param int $user =null account_id to use if not current user
489
-	 * @return Iterator ident_id => identity_name of identity
489
+	 * @return Api\Db\CallbackIterator ident_id => identity_name of identity
490 490
 	 */
491 491
 	public static function identities($account, $replace_placeholders=true, $field='name', $user=null)
492 492
 	{
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
 	 *
796 796
 	 * To get $this->params you need to call getUserData before! It is never automatically loaded.
797 797
 	 *
798
-	 * @param type $name
798
+	 * @param string $name
799 799
 	 * @return mixed
800 800
 	 */
801 801
 	public function __get($name)
@@ -819,8 +819,8 @@  discard block
 block discarded – undo
819 819
 	/**
820 820
 	 * Give read access to protected parameters in $this->params
821 821
 	 *
822
-	 * @param type $name
823
-	 * @return mixed
822
+	 * @param string $name
823
+	 * @return boolean
824 824
 	 */
825 825
 	public function __isset($name)
826 826
 	{
@@ -1340,10 +1340,10 @@  discard block
 block discarded – undo
1340 1340
 	 * @param boolean|string $just_name =true true: return self::identity_name, false: return Account objects,
1341 1341
 	 *	string with attribute-name: return that attribute, eg. acc_imap_host or 'params' to return all attributes as array
1342 1342
 	 * @param string $order_by ='acc_name ASC'
1343
-	 * @param int|boolean $offset =false offset or false to return all
1343
+	 * @param boolean $offset =false offset or false to return all
1344 1344
 	 * @param int $num_rows =0 number of rows to return, 0=default from prefs (if $offset !== false)
1345 1345
 	 * @param boolean $replace_placeholders =true should placeholders like {{n_fn}} be replaced
1346
-	 * @return Iterator with acc_id => acc_name or Account objects
1346
+	 * @return Api\Db\CallbackIterator with acc_id => acc_name or Account objects
1347 1347
 	 */
1348 1348
 	public static function search($only_current_user=true, $just_name=true, $order_by=null, $offset=false, $num_rows=0, $replace_placeholders=true)
1349 1349
 	{
Please login to merge, or discard this patch.
Spacing   +66 added lines, -69 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	/**
198 198
 	 * Path to log smtp comunication to or null to not log
199 199
 	 */
200
-	const SMTP_DEBUG_LOG = null;//'/tmp/smtp.log';
200
+	const SMTP_DEBUG_LOG = null; //'/tmp/smtp.log';
201 201
 
202 202
 	/**
203 203
 	 * Instanciated account object by acc_id, read acts as singelton
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 * @param int $called_for=null if set access to given user (without smtp credentials!),
246 246
 	 *	default current user AND read username/password from current users session
247 247
 	 */
248
-	/*protected*/ function __construct(array $params, $called_for=null)
248
+	/*protected*/ function __construct(array $params, $called_for = null)
249 249
 	{
250 250
 		// read credentials from database
251 251
 		$params += Credentials::read($params['acc_id'], null, $called_for ? array(0, $called_for) : $called_for);
@@ -274,16 +274,16 @@  discard block
 block discarded – undo
274 274
 	public static function ssl2secure($ssl)
275 275
 	{
276 276
 		$secure = false;
277
-		switch($ssl & ~self::SSL_VERIFY)
277
+		switch ($ssl&~self::SSL_VERIFY)
278 278
 		{
279 279
 			case self::SSL_STARTTLS:
280
-				$secure = 'tls';	// Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
280
+				$secure = 'tls'; // Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
281 281
 				break;
282 282
 			case self::SSL_SSL:
283 283
 				$secure = 'ssl';
284 284
 				break;
285 285
 			case self::SSL_TLS:
286
-				$secure = 'tlsv1';	// since Horde_Imap_Client-1.16.0 requiring Horde_Socket_Client-1.1.0
286
+				$secure = 'tlsv1'; // since Horde_Imap_Client-1.16.0 requiring Horde_Socket_Client-1.1.0
287 287
 				break;
288 288
 		}
289 289
 		return $secure;
@@ -312,15 +312,15 @@  discard block
 block discarded – undo
312 312
 				$this->params = array_merge($this->params, $data);
313 313
 			}
314 314
 		}
315
-		catch(Horde_Imap_Client_Exception $e) {
315
+		catch (Horde_Imap_Client_Exception $e) {
316 316
 			unset($e);
317 317
 			// ignore eg. connection errors
318 318
 		}
319
-		catch(\InvalidArgumentException $e) {
319
+		catch (\InvalidArgumentException $e) {
320 320
 			unset($e);
321 321
 			// ignore eg. missing admin user
322 322
 		}
323
-		$this->params += array_fill_keys(self::$user_data, null);	// make sure all keys exist now
323
+		$this->params += array_fill_keys(self::$user_data, null); // make sure all keys exist now
324 324
 
325 325
 		return (array)$data + (array)$smtp_data;
326 326
 	}
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 	 * @param int $_timeout =null timeout in secs, if none given fmail pref or default of 20 is used
355 355
 	 * @return Imap
356 356
 	 */
357
-	public function imapServer($_adminConnection=false, $_timeout=null)
357
+	public function imapServer($_adminConnection = false, $_timeout = null)
358 358
 	{
359 359
 		if (!isset($this->imapServer) || $this->imapServer->isAdminConnection !== $_adminConnection)
360 360
 		{
@@ -378,11 +378,11 @@  discard block
 block discarded – undo
378 378
 	 *	(matters only for imap servers managed by EGroupware!)
379 379
 	 * @return boolean
380 380
 	 */
381
-	public function is_imap($try_connect=true)
381
+	public function is_imap($try_connect = true)
382 382
 	{
383 383
 		if (empty($this->acc_imap_host) || empty($this->acc_imap_username) || empty($this->acc_imap_password))
384 384
 		{
385
-			return false;	// no imap host or credentials
385
+			return false; // no imap host or credentials
386 386
 		}
387 387
 		// if we are not managing the mail-server, we do NOT need to check deliveryMode and accountStatus
388 388
 		if ($this->acc_smtp_type == __NAMESPACE__.'\\Smtp')
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 			$this->smtpServer->editForwardingAddress = false;
420 420
 			$this->smtpServer->host = $this->params['acc_smtp_host'];
421 421
 			$this->smtpServer->port = $this->params['acc_smtp_port'];
422
-			switch($this->params['acc_smtp_ssl'])
422
+			switch ($this->params['acc_smtp_ssl'])
423 423
 			{
424 424
 				case self::SSL_TLS:
425 425
 					$this->smtpServer->host = 'tlsv1://'.$this->smtpServer->host;
@@ -449,16 +449,16 @@  discard block
 block discarded – undo
449 449
 		if (!isset($this->smtpTransport))
450 450
 		{
451 451
 			$secure = false;
452
-			switch($this->acc_smtp_ssl & ~self::SSL_VERIFY)
452
+			switch ($this->acc_smtp_ssl&~self::SSL_VERIFY)
453 453
 			{
454 454
 				case self::SSL_STARTTLS:
455
-					$secure = 'tls';	// Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
455
+					$secure = 'tls'; // Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
456 456
 					break;
457 457
 				case self::SSL_SSL:
458 458
 					$secure = 'ssl';
459 459
 					break;
460 460
 				case self::SSL_TLS:
461
-					$secure = 'tlsv1';	// since Horde_Smtp-1.3.0 requiring Horde_Socket_Client-1.1.0
461
+					$secure = 'tlsv1'; // since Horde_Smtp-1.3.0 requiring Horde_Socket_Client-1.1.0
462 462
 					break;
463 463
 			}
464 464
 			// Horde use locale for translation of error messages
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 	 * @param int $user =null account_id to use if not current user
489 489
 	 * @return Iterator ident_id => identity_name of identity
490 490
 	 */
491
-	public static function identities($account, $replace_placeholders=true, $field='name', $user=null)
491
+	public static function identities($account, $replace_placeholders = true, $field = 'name', $user = null)
492 492
 	{
493 493
 		if (!isset($user)) $user = $GLOBALS['egw_info']['user']['account_id'];
494 494
 		$acc_id = is_scalar($account) ? $account : $account['acc_id'];
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 				}
539 539
 				return self::identity_name($row, $replace_placeholders);
540 540
 			}, array(),
541
-			function($row) { return $row['ident_id'];});
541
+			function($row) { return $row['ident_id']; });
542 542
 	}
543 543
 
544 544
 	/**
@@ -581,17 +581,17 @@  discard block
 block discarded – undo
581 581
 	 * @return array acc_id:ident_id:email => rfc822 address pairs, eg. '1:1:[email protected]' => 'Ralf Becker Stylite AG <[email protected]>'
582 582
 	 * @todo add aliases for manged mail servers
583 583
 	 */
584
-	public static function rfc822_addresses($formatter=null)
584
+	public static function rfc822_addresses($formatter = null)
585 585
 	{
586 586
 		if (!$formatter || !is_callable($formatter))
587 587
 		{
588 588
 			$formatter = 'self::rfc822';
589 589
 		}
590 590
 		$addresses = array();
591
-		foreach(self::search(true, false) as $acc_id => $account)
591
+		foreach (self::search(true, false) as $acc_id => $account)
592 592
 		{
593
-			$added = false;	// make sure each account get's at least added once, even if it uses an identical email address
594
-			foreach(self::identities($account, true, 'params') as $identity)
593
+			$added = false; // make sure each account get's at least added once, even if it uses an identical email address
594
+			foreach (self::identities($account, true, 'params') as $identity)
595 595
 			{
596 596
 				if (($address = call_user_func($formatter, $identity)) && (!$added || !in_array($address, $addresses)))
597 597
 				{
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
 			}
626 626
 			return $cmp;
627 627
 		});
628
-		foreach($identities as &$identity)
628
+		foreach ($identities as &$identity)
629 629
 		{
630 630
 			$identity = self::identity_name($identity);
631 631
 		}
@@ -642,16 +642,16 @@  discard block
 block discarded – undo
642 642
 	 * @param int $account_id =null account_id of user, or current user
643 643
 	 * @return array with modified fields
644 644
 	 */
645
-	public static function replace_placeholders($identity, $account_id=null)
645
+	public static function replace_placeholders($identity, $account_id = null)
646 646
 	{
647
-		static $fields = array('ident_name','ident_realname','ident_org','ident_email','ident_signature');
647
+		static $fields = array('ident_name', 'ident_realname', 'ident_org', 'ident_email', 'ident_signature');
648 648
 
649 649
 		if (!is_array($identity) && !is_a($identity, 'Account'))
650 650
 		{
651 651
 			throw new Api\Exception\WrongParameter(__METHOD__."() requires an identity or account as first parameter!");
652 652
 		}
653 653
 		$to_replace = array();
654
-		foreach($fields as $name)
654
+		foreach ($fields as $name)
655 655
 		{
656 656
 			if (strpos($identity[$name], '{{') !== false || strpos($identity[$name], '$$') !== false)
657 657
 			{
@@ -660,10 +660,10 @@  discard block
 block discarded – undo
660 660
 		}
661 661
 		if ($to_replace)
662 662
 		{
663
-			static $merge=null;
663
+			static $merge = null;
664 664
 			if (!isset($merge)) $merge = new Api\Contacts\Merge();
665 665
 			if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
666
-			foreach($to_replace as $name => &$value)
666
+			foreach ($to_replace as $name => &$value)
667 667
 			{
668 668
 				$err = null;
669 669
 				$value = $merge->merge_string($value,
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
 	 * @return array
686 686
 	 * @throws Api\Exception\NotFound
687 687
 	 */
688
-	public static function read_identity($ident_id, $replace_placeholders=false, $user=null, $account=null)
688
+	public static function read_identity($ident_id, $replace_placeholders = false, $user = null, $account = null)
689 689
 	{
690 690
 		if (($account && $account['ident_id'] == $ident_id))
691 691
 		{
@@ -755,8 +755,7 @@  discard block
 block discarded – undo
755 755
 			'ident_org' => $identity['ident_org'],
756 756
 			'ident_email' => $identity['ident_email'],
757 757
 			'ident_signature' => $identity['ident_signature'],
758
-			'account_id' => self::is_multiple($identity) ? 0 :
759
-				(is_array($identity['account_id']) ? $identity['account_id'][0] : $identity['account_id']),
758
+			'account_id' => self::is_multiple($identity) ? 0 : (is_array($identity['account_id']) ? $identity['account_id'][0] : $identity['account_id']),
760 759
 		);
761 760
 		if ($identity['ident_id'] > 0)
762 761
 		{
@@ -800,7 +799,7 @@  discard block
 block discarded – undo
800 799
 	 */
801 800
 	public function __get($name)
802 801
 	{
803
-		switch($name)
802
+		switch ($name)
804 803
 		{
805 804
 			case 'acc_imap_administration':	// no longer stored in database
806 805
 				return !empty($this->params['acc_imap_admin_username']);
@@ -824,7 +823,7 @@  discard block
 block discarded – undo
824 823
 	 */
825 824
 	public function __isset($name)
826 825
 	{
827
-		switch($name)
826
+		switch ($name)
828 827
 		{
829 828
 			case 'acc_imap_administration':	// no longer stored in database
830 829
 				return true;
@@ -914,11 +913,11 @@  discard block
 block discarded – undo
914 913
 		{
915 914
 			// check if account is for current user, if not deny access
916 915
 			$memberships = self::memberships();
917
-			$memberships[] = '';	// edit uses '' for everyone
916
+			$memberships[] = ''; // edit uses '' for everyone
918 917
 
919 918
 			if (array_intersect((array)$account['account_id'], $memberships))
920 919
 			{
921
-				switch($rights)
920
+				switch ($rights)
922 921
 				{
923 922
 					case Api\Acl::READ:
924 923
 						$access = true;
@@ -963,7 +962,7 @@  discard block
 block discarded – undo
963 962
 	 * @return email_account
964 963
 	 * @throws Api\Exception\NotFound if account was not found (or not valid for current user)
965 964
 	 */
966
-	public static function read($acc_id, $called_for=null)
965
+	public static function read($acc_id, $called_for = null)
967 966
 	{
968 967
 		//error_log(__METHOD__."($acc_id, ".array2string($called_for).")");
969 968
 		// some caching, but only for regular usage/users
@@ -981,7 +980,7 @@  discard block
 block discarded – undo
981 980
 				//error_log(__METHOD__."($acc_id) created instance from cached data");
982 981
 				return self::$instances[$acc_id] = new Account(self::$cache[$acc_id]);
983 982
 			}
984
-			$data =& self::$cache[$acc_id];
983
+			$data = & self::$cache[$acc_id];
985 984
 		}
986 985
 		$where = array(self::TABLE.'.acc_id='.(int)$acc_id);
987 986
 		if (!isset($called_for) || $called_for !== '0')
@@ -1005,7 +1004,7 @@  discard block
 block discarded – undo
1005 1004
 		if (!$valid_account_id_sql)
1006 1005
 		{
1007 1006
 			$data['account_id'] = array();
1008
-			foreach(self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $acc_id),
1007
+			foreach (self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $acc_id),
1009 1008
 				__LINE__, __FILE__, false, '', self::APP) as $row)
1010 1009
 			{
1011 1010
 				$data['account_id'][] = $row['account_id'];
@@ -1017,7 +1016,7 @@  discard block
 block discarded – undo
1017 1016
 		if (!isset($called_for))
1018 1017
 		{
1019 1018
 			//error_log(__METHOD__."($acc_id) creating instance and caching data read from db");
1020
-			$ret =& self::$instances[$acc_id];
1019
+			$ret = & self::$instances[$acc_id];
1021 1020
 		}
1022 1021
 		return $ret = new Account($data, $called_for);
1023 1022
 	}
@@ -1030,7 +1029,7 @@  discard block
 block discarded – undo
1030 1029
 	 */
1031 1030
 	protected static function db2data(array $data)
1032 1031
 	{
1033
-		foreach(array('acc_sieve_enabled','acc_further_identities','acc_user_editable','acc_smtp_auth_session','acc_user_forward') as $name)
1032
+		foreach (array('acc_sieve_enabled', 'acc_further_identities', 'acc_user_editable', 'acc_smtp_auth_session', 'acc_user_forward') as $name)
1034 1033
 		{
1035 1034
 			if (isset($data[$name]))
1036 1035
 			{
@@ -1129,16 +1128,16 @@  discard block
 block discarded – undo
1129 1128
 	 * @throws Api\Exception\WrongParameter if called static without data-array
1130 1129
 	 * @throws Api\Db\Exception
1131 1130
 	 */
1132
-	public static function write(array $data, $user=null)
1131
+	public static function write(array $data, $user = null)
1133 1132
 	{
1134 1133
 		//error_log(__METHOD__."(".array2string($data).")");
1135 1134
 		$data['acc_modifier'] = $GLOBALS['egw_info']['user']['account_id'];
1136 1135
 		$data['acc_modified'] = time();
1137 1136
 
1138 1137
 		// remove redundant namespace to fit into column
1139
-		$ns_len = strlen(__NAMESPACE__)+1;
1138
+		$ns_len = strlen(__NAMESPACE__) + 1;
1140 1139
 		$backup = array();
1141
-		foreach(array('acc_smtp_type', 'acc_imap_type') as $attr)
1140
+		foreach (array('acc_smtp_type', 'acc_imap_type') as $attr)
1142 1141
 		{
1143 1142
 			if (substr($data[$attr], 0, $ns_len) == __NAMESPACE__.'\\')
1144 1143
 			{
@@ -1152,7 +1151,7 @@  discard block
 block discarded – undo
1152 1151
 		{
1153 1152
 			// set not set values which, are NOT NULL and therefore would give an SQL error
1154 1153
 			$td = self::$db->get_table_definitions('api', self::TABLE);
1155
-			foreach($td['fd'] as $col => $def)
1154
+			foreach ($td['fd'] as $col => $def)
1156 1155
 			{
1157 1156
 				if (!isset($data[$col]) && $def['nullable'] === false && !isset($def['default']))
1158 1157
 				{
@@ -1189,19 +1188,19 @@  discard block
 block discarded – undo
1189 1188
 		$old_account_ids = array();
1190 1189
 		if ($where)
1191 1190
 		{
1192
-			foreach(self::$db->select(self::VALID_TABLE, 'account_id', $where,
1191
+			foreach (self::$db->select(self::VALID_TABLE, 'account_id', $where,
1193 1192
 				__LINE__, __FILE__, false, '', self::APP) as $row)
1194 1193
 			{
1195 1194
 				$old_account_ids[] = $row['account_id'];
1196 1195
 			}
1197 1196
 			if (($ids_to_remove = array_diff($old_account_ids, (array)$data['account_id'])))
1198 1197
 			{
1199
-				self::$db->delete(self::VALID_TABLE, $where+array(
1198
+				self::$db->delete(self::VALID_TABLE, $where + array(
1200 1199
 					'account_id' => $ids_to_remove,
1201 1200
 				), __LINE__, __FILE__, self::APP);
1202 1201
 			}
1203 1202
 		}
1204
-		foreach((array)$data['account_id'] as $account_id)
1203
+		foreach ((array)$data['account_id'] as $account_id)
1205 1204
 		{
1206 1205
 			if (!in_array($account_id, $old_account_ids))
1207 1206
 			{
@@ -1238,8 +1237,7 @@  discard block
 block discarded – undo
1238 1237
 		}
1239 1238
 
1240 1239
 		// store notification folders
1241
-		Notifications::write($data['acc_id'], $data['notify_save_default'] ? 0 :
1242
-			($data['called_for'] ? $data['called_for'] : $GLOBALS['egw_info']['user']['account_id']),
1240
+		Notifications::write($data['acc_id'], $data['notify_save_default'] ? 0 : ($data['called_for'] ? $data['called_for'] : $GLOBALS['egw_info']['user']['account_id']),
1243 1241
 			(array)$data['notify_folders']);
1244 1242
 
1245 1243
 		// store domain of an account for all user like before as "mail_suffix" config
@@ -1265,7 +1263,7 @@  discard block
 block discarded – undo
1265 1263
 	 * @param int $account_id =null
1266 1264
 	 * @return boolean
1267 1265
 	 */
1268
-	protected static function credentials_valid_for($account, $account_id=null)
1266
+	protected static function credentials_valid_for($account, $account_id = null)
1269 1267
 	{
1270 1268
 		if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
1271 1269
 
@@ -1291,7 +1289,7 @@  discard block
 block discarded – undo
1291 1289
 	 * @param int $account_id =null user or group
1292 1290
 	 * @return int number of deleted mail accounts or null if only user-data was deleted and no full mail accounts
1293 1291
 	 */
1294
-	public static function delete($acc_id, $account_id=null)
1292
+	public static function delete($acc_id, $account_id = null)
1295 1293
 	{
1296 1294
 		if (is_array($acc_id) || $acc_id > 0)
1297 1295
 		{
@@ -1302,7 +1300,7 @@  discard block
 block discarded – undo
1302 1300
 			self::$db->delete(self::TABLE, array('acc_id' => $acc_id), __LINE__, __FILE__, self::APP);
1303 1301
 
1304 1302
 			// invalidate caches
1305
-			foreach((array)$acc_id as $acc_id)
1303
+			foreach ((array)$acc_id as $acc_id)
1306 1304
 			{
1307 1305
 				self::cache_invalidate($acc_id);
1308 1306
 			}
@@ -1321,7 +1319,7 @@  discard block
 block discarded – undo
1321 1319
 		self::$db->delete(self::IDENTITIES_TABLE, array('account_id' => $account_id), __LINE__, __FILE__, self::APP);
1322 1320
 		// find profiles not belonging to anyone else and delete them
1323 1321
 		$acc_ids = array();
1324
-		foreach(self::$db->select(self::TABLE, self::TABLE.'.acc_id', 'account_id IS NULL', __LINE__, __FILE__,
1322
+		foreach (self::$db->select(self::TABLE, self::TABLE.'.acc_id', 'account_id IS NULL', __LINE__, __FILE__,
1325 1323
 			false, 'GROUP BY '.self::TABLE.'.acc_id', self::APP, 0, 'LEFT '.self::VALID_JOIN) as $row)
1326 1324
 		{
1327 1325
 			$acc_ids[] = $row['acc_id'];
@@ -1345,7 +1343,7 @@  discard block
 block discarded – undo
1345 1343
 	 * @param boolean $replace_placeholders =true should placeholders like {{n_fn}} be replaced
1346 1344
 	 * @return Iterator with acc_id => acc_name or Account objects
1347 1345
 	 */
1348
-	public static function search($only_current_user=true, $just_name=true, $order_by=null, $offset=false, $num_rows=0, $replace_placeholders=true)
1346
+	public static function search($only_current_user = true, $just_name = true, $order_by = null, $offset = false, $num_rows = 0, $replace_placeholders = true)
1349 1347
 	{
1350 1348
 		//error_log(__METHOD__."($only_current_user, $just_name, '$order_by', $offset, $num_rows)");
1351 1349
 		$where = array();
@@ -1391,19 +1389,19 @@  discard block
 block discarded – undo
1391 1389
 				$cols[] = self::ADMIN_COL;
1392 1390
 				$join .= ' '.self::ADMIN_JOIN;
1393 1391
 			}
1394
-			$rs = self::$db->select(self::TABLE, $cols,	$where, __LINE__, __FILE__,
1392
+			$rs = self::$db->select(self::TABLE, $cols, $where, __LINE__, __FILE__,
1395 1393
 				$offset, Api\Storage::fix_group_by_columns($group_by, $cols, self::TABLE, 'acc_id').' ORDER BY '.$order_by,
1396 1394
 				self::APP, $num_rows, $join);
1397 1395
 
1398 1396
 			$ids = array();
1399
-			foreach($rs as $row)
1397
+			foreach ($rs as $row)
1400 1398
 			{
1401 1399
 				$row = self::db2data($row);
1402 1400
 
1403 1401
 				if ($only_current_user === true)
1404 1402
 				{
1405 1403
 					//error_log(__METHOD__."(TRUE, $just_name) caching data for acc_id=$row[acc_id]");
1406
-					self::$search_cache[$cache_key][$row['acc_id']] =& self::$cache[$row['acc_id']];
1404
+					self::$search_cache[$cache_key][$row['acc_id']] = & self::$cache[$row['acc_id']];
1407 1405
 					self::$cache[$row['acc_id']] = $row;
1408 1406
 				}
1409 1407
 				else
@@ -1415,14 +1413,14 @@  discard block
 block discarded – undo
1415 1413
 			// fetch valid_id, if not yet fetched
1416 1414
 			if (!$valid_account_id_sql && $ids)
1417 1415
 			{
1418
-				foreach(self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $ids),
1416
+				foreach (self::$db->select(self::VALID_TABLE, 'account_id', array('acc_id' => $ids),
1419 1417
 					__LINE__, __FILE__, false, '', self::APP) as $row)
1420 1418
 				{
1421 1419
 					self::$cache[$row['acc_id']]['account_id'][] = $row['account_id'];
1422 1420
 				}
1423 1421
 			}
1424 1422
 		}
1425
-		if (is_null(self::$search_cache[$cache_key])) self::$search_cache[$cache_key]=array();
1423
+		if (is_null(self::$search_cache[$cache_key])) self::$search_cache[$cache_key] = array();
1426 1424
 		return new Api\Db\CallbackIterator(new \ArrayIterator(self::$search_cache[$cache_key]),
1427 1425
 			// process each row
1428 1426
 			function($row) use ($just_name, $replace_placeholders, $account_id)
@@ -1456,11 +1454,11 @@  discard block
 block discarded – undo
1456 1454
 	 * @param boolean $log_no_default =true true: error_log if no default found, false be silent
1457 1455
 	 * @return Account|null
1458 1456
 	 */
1459
-	static function get_default($smtp=false, $return_id=false, $log_no_default=true)
1457
+	static function get_default($smtp = false, $return_id = false, $log_no_default = true)
1460 1458
 	{
1461 1459
 		try
1462 1460
 		{
1463
-			foreach(self::search(true, 'params') as $acc_id => $params)
1461
+			foreach (self::search(true, 'params') as $acc_id => $params)
1464 1462
 			{
1465 1463
 				if ($smtp)
1466 1464
 				{
@@ -1507,7 +1505,7 @@  discard block
 block discarded – undo
1507 1505
 	 * @param boolean $smtp =false false: usable for IMAP, true: usable for SMTP
1508 1506
 	 * @return int
1509 1507
 	 */
1510
-	static function get_default_acc_id($smtp=false)
1508
+	static function get_default_acc_id($smtp = false)
1511 1509
 	{
1512 1510
 		return self::get_default($smtp, true);
1513 1511
 	}
@@ -1520,7 +1518,7 @@  discard block
 block discarded – undo
1520 1518
 	 * @param int $account_id =null account_id of user we are called for
1521 1519
 	 * @return string with htmlencoded angle brackets
1522 1520
 	 */
1523
-	public static function identity_name($account, $replace_placeholders=true, $account_id=null)
1521
+	public static function identity_name($account, $replace_placeholders = true, $account_id = null)
1524 1522
 	{
1525 1523
 		if ($replace_placeholders)
1526 1524
 		{
@@ -1547,7 +1545,7 @@  discard block
 block discarded – undo
1547 1545
 				{
1548 1546
 					if (!isset($account['acc_imap_username']))
1549 1547
 					{
1550
-						$account += Credentials::read($account['acc_id'], null, ($account_id?array($account_id, 0):null));
1548
+						$account += Credentials::read($account['acc_id'], null, ($account_id ? array($account_id, 0) : null));
1551 1549
 					}
1552 1550
 					if (empty($account['acc_imap_username']) && $account['acc_imap_logintype'] &&
1553 1551
 						(!isset($account_id) || $account_id == $GLOBALS['egw_info']['user']['account_id']))
@@ -1566,7 +1564,7 @@  discard block
 block discarded – undo
1566 1564
 					$account['ident_email'] = $account['acc_imap_username'];
1567 1565
 				}
1568 1566
 			}
1569
-			catch(\Exception $e) {
1567
+			catch (\Exception $e) {
1570 1568
 				_egw_log_exception($e);
1571 1569
 			}
1572 1570
 
@@ -1583,7 +1581,7 @@  discard block
 block discarded – undo
1583 1581
 		{
1584 1582
 			$name .= ' <'.$account['ident_email'].'>';
1585 1583
 		}
1586
-		elseif(strpos($account['acc_imap_username'], '@') !== false)
1584
+		elseif (strpos($account['acc_imap_username'], '@') !== false)
1587 1585
 		{
1588 1586
 			$name .= ' <'.$account['acc_imap_username'].'>';
1589 1587
 		}
@@ -1606,8 +1604,7 @@  discard block
 block discarded – undo
1606 1604
 	 */
1607 1605
 	public static function is_multiple($account)
1608 1606
 	{
1609
-		$is_multiple = !is_array($account['account_id']) ? $account['account_id'] <= 0 :
1610
-			(count($account['account_id']) > 1 || $account['account_id'][0] <= 0);
1607
+		$is_multiple = !is_array($account['account_id']) ? $account['account_id'] <= 0 : (count($account['account_id']) > 1 || $account['account_id'][0] <= 0);
1611 1608
 		//error_log(__METHOD__."(account_id=".array2string($account['account_id']).") returning ".array2string($is_multiple));
1612 1609
 		return $is_multiple;
1613 1610
 	}
@@ -1628,13 +1625,13 @@  discard block
 block discarded – undo
1628 1625
 	 * @param type $user
1629 1626
 	 * @return array
1630 1627
 	 */
1631
-	protected static function memberships($user=null)
1628
+	protected static function memberships($user = null)
1632 1629
 	{
1633 1630
 		if (!$user) $user = $GLOBALS['egw_info']['user']['account_id'];
1634 1631
 
1635 1632
 		$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
1636 1633
 		$memberships[] = $user;
1637
-		$memberships[] = 0;	// marks accounts valid for everyone
1634
+		$memberships[] = 0; // marks accounts valid for everyone
1638 1635
 
1639 1636
 		return $memberships;
1640 1637
 	}
Please login to merge, or discard this patch.
Braces   +95 added lines, -24 removed lines patch added patch discarded remove patch
@@ -360,8 +360,14 @@  discard block
 block discarded – undo
360 360
 		{
361 361
 			// make sure mbstring.func_overload=0
362 362
 			static $func_overload = null;
363
-			if (is_null($func_overload)) $func_overload = extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
364
-			if ($func_overload) throw new Api\Exception\AssertionFailed('Fatal Error: EGroupware requires mbstring.func_overload=0 set in your php.ini!');
363
+			if (is_null($func_overload))
364
+			{
365
+				$func_overload = extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
366
+			}
367
+			if ($func_overload)
368
+			{
369
+				throw new Api\Exception\AssertionFailed('Fatal Error: EGroupware requires mbstring.func_overload=0 set in your php.ini!');
370
+			}
365 371
 
366 372
 			$class = $this->params['acc_imap_type'];
367 373
 			$this->imapServer = new $class($this->params, $_adminConnection, $_timeout);
@@ -490,7 +496,10 @@  discard block
 block discarded – undo
490 496
 	 */
491 497
 	public static function identities($account, $replace_placeholders=true, $field='name', $user=null)
492 498
 	{
493
-		if (!isset($user)) $user = $GLOBALS['egw_info']['user']['account_id'];
499
+		if (!isset($user))
500
+		{
501
+			$user = $GLOBALS['egw_info']['user']['account_id'];
502
+		}
494 503
 		$acc_id = is_scalar($account) ? $account : $account['acc_id'];
495 504
 
496 505
 		$cols = array('ident_id', 'ident_name', 'ident_realname', 'ident_org', 'ident_email', 'ident_signature', 'acc_id', 'acc_imap_username', 'acc_imap_logintype', 'acc_domain');
@@ -528,8 +537,14 @@  discard block
 block discarded – undo
528 537
 				// fill an empty ident_realname or ident_email of current user with data from user account
529 538
 				if ($replace_placeholders && (!isset($user) || $user == $GLOBALS['egw_info']['user']['acount_id']))
530 539
 				{
531
-					if (empty($row['ident_realname'])) $row['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
532
-					if (empty($row['ident_email'])) $row['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
540
+					if (empty($row['ident_realname']))
541
+					{
542
+						$row['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
543
+					}
544
+					if (empty($row['ident_email']))
545
+					{
546
+						$row['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
547
+					}
533 548
 				}
534 549
 				if ($field != 'name')
535 550
 				{
@@ -538,7 +553,9 @@  discard block
 block discarded – undo
538 553
 				}
539 554
 				return self::identity_name($row, $replace_placeholders);
540 555
 			}, array(),
541
-			function($row) { return $row['ident_id'];});
556
+			function($row)
557
+			{
558
+return $row['ident_id'];});
542 559
 	}
543 560
 
544 561
 	/**
@@ -554,10 +571,13 @@  discard block
 block discarded – undo
554 571
 		{
555 572
 			$address .= ($address && $identity['ident_org'] ? ' ' : '').$identity['ident_org'];
556 573
 		}
557
-		if (strpos($address, ',') !== false)	// need to quote comma
574
+		if (strpos($address, ',') !== false)
575
+		{
576
+			// need to quote comma
558 577
 		{
559 578
 			$address = '"'.str_replace('"', '\\"', $address).'"';
560 579
 		}
580
+		}
561 581
 		if (!strpos($identity['ident_email'], '@'))
562 582
 		{
563 583
 			$address = null;
@@ -661,8 +681,14 @@  discard block
 block discarded – undo
661 681
 		if ($to_replace)
662 682
 		{
663 683
 			static $merge=null;
664
-			if (!isset($merge)) $merge = new Api\Contacts\Merge();
665
-			if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
684
+			if (!isset($merge))
685
+			{
686
+				$merge = new Api\Contacts\Merge();
687
+			}
688
+			if (!isset($account_id))
689
+			{
690
+				$account_id = $GLOBALS['egw_info']['user']['account_id'];
691
+			}
666 692
 			foreach($to_replace as $name => &$value)
667 693
 			{
668 694
 				$err = null;
@@ -1083,7 +1109,10 @@  discard block
 block discarded – undo
1083 1109
 				}
1084 1110
 
1085 1111
 				// fetch the IMAP / incomming server data
1086
-				if (!class_exists($data['acc_smtp_type'])) $data['acc_smtp_type'] = __NAMESPACE__.'\\Smtp';
1112
+				if (!class_exists($data['acc_smtp_type']))
1113
+				{
1114
+					$data['acc_smtp_type'] = __NAMESPACE__.'\\Smtp';
1115
+				}
1087 1116
 			}
1088 1117
 		}
1089 1118
 		return $data;
@@ -1115,7 +1144,10 @@  discard block
 block discarded – undo
1115 1144
 		}
1116 1145
 
1117 1146
 		// fetch the IMAP / incomming server data
1118
-		if (!class_exists($imap_type)) $imap_type = __NAMESPACE__.'\\Imap';
1147
+		if (!class_exists($imap_type))
1148
+		{
1149
+			$imap_type = __NAMESPACE__.'\\Imap';
1150
+		}
1119 1151
 
1120 1152
 		return $imap_type;
1121 1153
 	}
@@ -1168,7 +1200,10 @@  discard block
 block discarded – undo
1168 1200
 			$data['acc_id'] = self::$db->get_last_insert_id(self::TABLE, 'acc_id');
1169 1201
 		}
1170 1202
 		// restore namespace in class-names
1171
-		if ($backup) $data = array_merge($data, $backup);
1203
+		if ($backup)
1204
+		{
1205
+			$data = array_merge($data, $backup);
1206
+		}
1172 1207
 
1173 1208
 		// store identity
1174 1209
 		$new_ident_id = self::save_identity($data);
@@ -1267,7 +1302,10 @@  discard block
 block discarded – undo
1267 1302
 	 */
1268 1303
 	protected static function credentials_valid_for($account, $account_id=null)
1269 1304
 	{
1270
-		if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
1305
+		if (!isset($account_id))
1306
+		{
1307
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
1308
+		}
1271 1309
 
1272 1310
 		// if account valid for multiple users
1273 1311
 		if (self::is_multiple($account))
@@ -1386,9 +1424,12 @@  discard block
 block discarded – undo
1386 1424
 				$cols[] = $valid_account_id_sql.' AS account_id';
1387 1425
 				$join .= ' '.self::ALL_VALID_JOIN;
1388 1426
 			}
1389
-			if ($just_name == 'params')	// join in acc_imap_admin_username
1427
+			if ($just_name == 'params')
1428
+			{
1429
+				// join in acc_imap_admin_username
1390 1430
 			{
1391 1431
 				$cols[] = self::ADMIN_COL;
1432
+			}
1392 1433
 				$join .= ' '.self::ADMIN_JOIN;
1393 1434
 			}
1394 1435
 			$rs = self::$db->select(self::TABLE, $cols,	$where, __LINE__, __FILE__,
@@ -1422,7 +1463,10 @@  discard block
 block discarded – undo
1422 1463
 				}
1423 1464
 			}
1424 1465
 		}
1425
-		if (is_null(self::$search_cache[$cache_key])) self::$search_cache[$cache_key]=array();
1466
+		if (is_null(self::$search_cache[$cache_key]))
1467
+		{
1468
+			self::$search_cache[$cache_key]=array();
1469
+		}
1426 1470
 		return new Api\Db\CallbackIterator(new \ArrayIterator(self::$search_cache[$cache_key]),
1427 1471
 			// process each row
1428 1472
 			function($row) use ($just_name, $replace_placeholders, $account_id)
@@ -1464,12 +1508,18 @@  discard block
 block discarded – undo
1464 1508
 			{
1465 1509
 				if ($smtp)
1466 1510
 				{
1467
-					if (!$params['acc_smtp_host'] || !$params['acc_smtp_port']) continue;
1511
+					if (!$params['acc_smtp_host'] || !$params['acc_smtp_port'])
1512
+					{
1513
+						continue;
1514
+					}
1468 1515
 					// check requirement of session, which is not available in async service!
1469 1516
 					if (isset($GLOBALS['egw_info']['flags']['async-service']) ||
1470
-						empty($GLOBALS['egw_info']['user']['account_id']))	// happens during login when notifying about blocked accounts
1517
+						empty($GLOBALS['egw_info']['user']['account_id']))
1518
+					{
1519
+						// happens during login when notifying about blocked accounts
1471 1520
 					{
1472 1521
 						if ($params['acc_smtp_auth_session']) continue;
1522
+					}
1473 1523
 						// may fail because of smtp only profile, or no session password, etc
1474 1524
 						try
1475 1525
 						{
@@ -1480,15 +1530,24 @@  discard block
 block discarded – undo
1480 1530
 							unset($x);
1481 1531
 							continue;
1482 1532
 						}
1483
-						if ($account->acc_smtp_pw_enc == Credentials::USER) continue;
1533
+						if ($account->acc_smtp_pw_enc == Credentials::USER)
1534
+						{
1535
+							continue;
1536
+						}
1484 1537
 					}
1485 1538
 				}
1486 1539
 				else
1487 1540
 				{
1488
-					if (!$params['acc_imap_host'] || !$params['acc_imap_port']) continue;
1541
+					if (!$params['acc_imap_host'] || !$params['acc_imap_port'])
1542
+					{
1543
+						continue;
1544
+					}
1489 1545
 					$account = new Account($params);
1490 1546
 					// continue if we have either no imap username or password
1491
-					if (!$account->is_imap()) continue;
1547
+					if (!$account->is_imap())
1548
+					{
1549
+						continue;
1550
+					}
1492 1551
 				}
1493 1552
 				return $return_id ? $acc_id : (isset($account) && $account->acc_id == $acc_id ?
1494 1553
 					$account : new Account($params));
@@ -1496,7 +1555,10 @@  discard block
 block discarded – undo
1496 1555
 		}
1497 1556
 		catch (\Exception $e)
1498 1557
 		{
1499
-			if ($log_no_default) error_log(__METHOD__.__LINE__.' Error no Default available.'.$e->getMessage());
1558
+			if ($log_no_default)
1559
+			{
1560
+				error_log(__METHOD__.__LINE__.' Error no Default available.'.$e->getMessage());
1561
+			}
1500 1562
 		}
1501 1563
 		return null;
1502 1564
 	}
@@ -1558,8 +1620,14 @@  discard block
 block discarded – undo
1558 1620
 				// fill an empty ident_realname or ident_email of current user with data from user account
1559 1621
 				if ($replace_placeholders && (!isset($account_id) || $account_id == $GLOBALS['egw_info']['user']['acount_id']))
1560 1622
 				{
1561
-					if (empty($account['ident_realname'])) $account['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
1562
-					if (empty($account['ident_email'])) $account['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
1623
+					if (empty($account['ident_realname']))
1624
+					{
1625
+						$account['ident_realname'] = $GLOBALS['egw_info']['user']['account_fullname'];
1626
+					}
1627
+					if (empty($account['ident_email']))
1628
+					{
1629
+						$account['ident_email'] = $GLOBALS['egw_info']['user']['account_email'];
1630
+					}
1563 1631
 				}
1564 1632
 				if (empty($account['ident_email']) && !empty($account['acc_imap_username']) && strpos($account['acc_imap_username'], '@') !== false)
1565 1633
 				{
@@ -1630,7 +1698,10 @@  discard block
 block discarded – undo
1630 1698
 	 */
1631 1699
 	protected static function memberships($user=null)
1632 1700
 	{
1633
-		if (!$user) $user = $GLOBALS['egw_info']['user']['account_id'];
1701
+		if (!$user)
1702
+		{
1703
+			$user = $GLOBALS['egw_info']['user']['account_id'];
1704
+		}
1634 1705
 
1635 1706
 		$memberships = $GLOBALS['egw']->accounts->memberships($user, true);
1636 1707
 		$memberships[] = $user;
Please login to merge, or discard this patch.
api/src/Mail/Credentials.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -322,6 +322,7 @@
 block discarded – undo
322 322
 	 * @param int $account_id user-account password is for
323 323
 	 * @param int &$pw_enc on return encryption used
324 324
 	 * @param ressource $mcrypt =null mcrypt ressource for user, default calling self::init_crypt(true)
325
+	 * @param integer $pw_enc
325 326
 	 * @return string encrypted password
326 327
 	 */
327 328
 	protected static function encrypt($password, $account_id, &$pw_enc, $mcrypt=null)
Please login to merge, or discard this patch.
Spacing   +28 added lines, -31 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @param int|array $account_id =null default use current user or all (in that order)
116 116
 	 * @return array with values for (imap|smtp|admin)_(username|password|cred_id)
117 117
 	 */
118
-	public static function read($acc_id, $type=null, $account_id=null)
118
+	public static function read($acc_id, $type = null, $account_id = null)
119 119
 	{
120 120
 		if (is_null($type)) $type = self::ALL;
121 121
 		if (is_null($account_id))
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 			$rows = self::$db->select(self::TABLE, '*', array(
132 132
 				'acc_id' => $acc_id,
133 133
 				'account_id' => $account_id,
134
-				'(cred_type & '.(int)$type.') > 0',	// postgreSQL require > 0, or gives error as it expects boolean
134
+				'(cred_type & '.(int)$type.') > 0', // postgreSQL require > 0, or gives error as it expects boolean
135 135
 			), __LINE__, __FILE__, false,
136 136
 				// account_id DESC ensures 0=all allways overwrite (old user-specific credentials)
137 137
 				'ORDER BY account_id ASC', self::APP);
@@ -139,14 +139,14 @@  discard block
 block discarded – undo
139 139
 		}
140 140
 		else
141 141
 		{
142
-			ksort($rows);	// ORDER BY account_id ASC
142
+			ksort($rows); // ORDER BY account_id ASC
143 143
 
144 144
 			// flatten account_id => cred_type => row array again, to have format like from database
145 145
 			$rows = call_user_func_array('array_merge', $rows);
146 146
 			//error_log(__METHOD__."($acc_id, $type, ".array2string($account_id).") read from cache ".array2string($rows));
147 147
 		}
148 148
 		$results = array();
149
-		foreach($rows as $row)
149
+		foreach ($rows as $row)
150 150
 		{
151 151
 			// update cache (only if we have database-iterator and all credentials asked!)
152 152
 			if (!is_array($rows) && $type == self::ALL)
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 			}
157 157
 			$password = self::decrypt($row);
158 158
 
159
-			foreach(self::$type2prefix as $pattern => $prefix)
159
+			foreach (self::$type2prefix as $pattern => $prefix)
160 160
 			{
161
-				if ($row['cred_type'] & $pattern)
161
+				if ($row['cred_type']&$pattern)
162 162
 				{
163 163
 					$results[$prefix.'username'] = $row['cred_username'];
164 164
 					$results[$prefix.'password'] = $password;
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
 	 * @param boolean $set_identity =true true: also set identity values realname&email, if not yet set
179 179
 	 * @return array with values for keys 'acc_(imap|smtp)_(username|password|cred_id)'
180 180
 	 */
181
-	public static function from_session(array $data, $set_identity=true)
181
+	public static function from_session(array $data, $set_identity = true)
182 182
 	{
183
-		switch($data['acc_imap_logintype'])
183
+		switch ($data['acc_imap_logintype'])
184 184
 		{
185 185
 			case 'standard':
186 186
 				$username = $GLOBALS['egw_info']['user']['account_lid'];
@@ -206,23 +206,21 @@  discard block
 block discarded – undo
206 206
 				throw new Api\Exception\WrongParameter("Unknown data[acc_imap_logintype]=".array2string($data['acc_imap_logintype']).'!');
207 207
 		}
208 208
 		$password = base64_decode(Api\Cache::getSession('phpgwapi', 'password'));
209
-		$realname = !$set_identity || $data['ident_realname'] ? $data['ident_realname'] :
210
-			$GLOBALS['egw_info']['user']['account_fullname'];
211
-		$email = !$set_identity || $data['ident_email'] ? $data['ident_email'] :
212
-			$GLOBALS['egw_info']['user']['account_email'];
209
+		$realname = !$set_identity || $data['ident_realname'] ? $data['ident_realname'] : $GLOBALS['egw_info']['user']['account_fullname'];
210
+		$email = !$set_identity || $data['ident_email'] ? $data['ident_email'] : $GLOBALS['egw_info']['user']['account_email'];
213 211
 
214 212
 		return array(
215 213
 			'ident_realname' => $realname,
216 214
 			'ident_email' => $email,
217 215
 			'acc_imap_username' => $username,
218 216
 			'acc_imap_password' => $password,
219
-			'acc_imap_cred_id'  => $data['acc_imap_logintype'],	// to NOT store it
217
+			'acc_imap_cred_id'  => $data['acc_imap_logintype'], // to NOT store it
220 218
 			'acc_imap_account_id' => 'c',
221 219
 		) + ($data['acc_smtp_auth_session'] ? array(
222 220
 			// only set smtp
223 221
 			'acc_smtp_username' => $username,
224 222
 			'acc_smtp_password' => $password,
225
-			'acc_smtp_cred_id'  => $data['acc_imap_logintype'],	// to NOT store it
223
+			'acc_smtp_cred_id'  => $data['acc_imap_logintype'], // to NOT store it
226 224
 			'acc_smtp_account_id' => 'c',
227 225
 		) : array());
228 226
 	}
@@ -239,27 +237,26 @@  discard block
 block discarded – undo
239 237
 	 * @param ressource $mcrypt =null mcrypt ressource for user, default calling self::init_crypt(true)
240 238
 	 * @return int cred_id
241 239
 	 */
242
-	public static function write($acc_id, $username, $password, $type, $account_id=0, $cred_id=null, $mcrypt=null)
240
+	public static function write($acc_id, $username, $password, $type, $account_id = 0, $cred_id = null, $mcrypt = null)
243 241
 	{
244 242
 		//error_log(__METHOD__."(acc_id=$acc_id, '$username', \$password, type=$type, account_id=$account_id, cred_id=$cred_id)");
245 243
 		if (!empty($cred_id) && !is_numeric($cred_id) || !is_numeric($account_id))
246 244
 		{
247 245
 			//error_log(__METHOD__."($acc_id, '$username', \$password, $type, $account_id, ".array2string($cred_id).") not storing session credentials!");
248
-			return;	// do NOT store credentials from session of current user!
246
+			return; // do NOT store credentials from session of current user!
249 247
 		}
250 248
 		// no need to write empty usernames, but delete existing row
251 249
 		if ((string)$username === '')
252 250
 		{
253 251
 			if ($cred_id) self::$db->delete(self::TABLE, array('cred_id' => $cred_id), __LINE__, __FILE__, self::APP);
254
-			return;	// nothing to save
252
+			return; // nothing to save
255 253
 		}
256 254
 		$pw_enc = self::CLEARTEXT;
257 255
 		$data = array(
258 256
 			'acc_id' => $acc_id,
259 257
 			'account_id' => $account_id,
260 258
 			'cred_username' => $username,
261
-			'cred_password' => (string)$password === '' ? '' :
262
-				self::encrypt($password, $account_id, $pw_enc, $mcrypt),
259
+			'cred_password' => (string)$password === '' ? '' : self::encrypt($password, $account_id, $pw_enc, $mcrypt),
263 260
 			'cred_type' => $type,
264 261
 			'cred_pw_enc' => $pw_enc,
265 262
 		);
@@ -292,7 +289,7 @@  discard block
 block discarded – undo
292 289
 	 * @param int $type =self::ALL self::IMAP, self::SMTP or self::ADMIN
293 290
 	 * @return int number of rows deleted
294 291
 	 */
295
-	public static function delete($acc_id, $account_id=null, $type=self::ALL)
292
+	public static function delete($acc_id, $account_id = null, $type = self::ALL)
296 293
 	{
297 294
 		if (!($acc_id > 0) && !isset($account_id))
298 295
 		{
@@ -301,12 +298,12 @@  discard block
 block discarded – undo
301 298
 		$where = array();
302 299
 		if ($acc_id > 0) $where['acc_id'] = $acc_id;
303 300
 		if (isset($account_id)) $where['account_id'] = $account_id;
304
-		if ($type != self::ALL) $where[] = '(cred_type & '.(int)$type.') > 0';	// postgreSQL require > 0, or gives error as it expects boolean
301
+		if ($type != self::ALL) $where[] = '(cred_type & '.(int)$type.') > 0'; // postgreSQL require > 0, or gives error as it expects boolean
305 302
 
306 303
 		self::$db->delete(self::TABLE, $where, __LINE__, __FILE__, self::APP);
307 304
 
308 305
 		// invalidate cache: we allways unset everything about an account to simplify cache handling
309
-		foreach($acc_id > 0 ? (array)$acc_id : array_keys(self::$cache) as $acc_id)
306
+		foreach ($acc_id > 0 ? (array)$acc_id : array_keys(self::$cache) as $acc_id)
310 307
 		{
311 308
 			unset(self::$cache[$acc_id]);
312 309
 		}
@@ -324,7 +321,7 @@  discard block
 block discarded – undo
324 321
 	 * @param ressource $mcrypt =null mcrypt ressource for user, default calling self::init_crypt(true)
325 322
 	 * @return string encrypted password
326 323
 	 */
327
-	protected static function encrypt($password, $account_id, &$pw_enc, $mcrypt=null)
324
+	protected static function encrypt($password, $account_id, &$pw_enc, $mcrypt = null)
328 325
 	{
329 326
 		if ($account_id > 0 && $account_id == $GLOBALS['egw_info']['user']['account_id'] &&
330 327
 			($mcrypt || ($mcrypt = self::init_crypt(true))))
@@ -351,7 +348,7 @@  discard block
 block discarded – undo
351 348
 	 * @param array $row database row
352 349
 	 * @param ressource $mcrypt =null mcrypt ressource for user, default calling self::init_crypt(true)
353 350
 	 */
354
-	protected static function decrypt(array $row, $mcrypt=null)
351
+	protected static function decrypt(array $row, $mcrypt = null)
355 352
 	{
356 353
 		switch ($row['cred_pw_enc'])
357 354
 		{
@@ -385,9 +382,9 @@  discard block
 block discarded – undo
385 382
 		if (empty($data['old_passwd'])) return;
386 383
 
387 384
 		$old_mcrypt = null;
388
-		foreach(self::$db->select(self::TABLE, self::TABLE.'.*', array(
385
+		foreach (self::$db->select(self::TABLE, self::TABLE.'.*', array(
389 386
 			'account_id' => $data['account_id']
390
-		),__LINE__, __FILE__, false, '', self::APP, 0, self::USER_EDITABLE_JOIN.self::$db->quote(true, 'bool')) as $row)
387
+		), __LINE__, __FILE__, false, '', self::APP, 0, self::USER_EDITABLE_JOIN.self::$db->quote(true, 'bool')) as $row)
391 388
 		{
392 389
 			if (!isset($old_mcrypt))
393 390
 			{
@@ -411,7 +408,7 @@  discard block
 block discarded – undo
411 408
 	 * @param string $mode ='ecb'
412 409
 	 * @return ressource|boolean mcrypt ressource to use or false if not available
413 410
 	 */
414
-	static public function init_crypt($user=false, $algo='tripledes',$mode='ecb')
411
+	static public function init_crypt($user = false, $algo = 'tripledes', $mode = 'ecb')
415 412
 	{
416 413
 		if (is_string($user))
417 414
 		{
@@ -419,11 +416,11 @@  discard block
 block discarded – undo
419 416
 		}
420 417
 		elseif ($user)
421 418
 		{
422
-			$mcrypt =& self::$user_mcrypt;
419
+			$mcrypt = & self::$user_mcrypt;
423 420
 		}
424 421
 		else
425 422
 		{
426
-			$mcrypt =& self::$system_mcrypt;
423
+			$mcrypt = & self::$system_mcrypt;
427 424
 		}
428 425
 		if (!isset($mcrypt))
429 426
 		{
@@ -459,10 +456,10 @@  discard block
 block discarded – undo
459 456
 			{
460 457
 				$iv_size = mcrypt_enc_get_iv_size($mcrypt);
461 458
 				$iv = !isset($GLOBALS['egw_info']['server']['mcrypt_iv']) || strlen($GLOBALS['egw_info']['server']['mcrypt_iv']) < $iv_size ?
462
-					mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size);
459
+					mcrypt_create_iv($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'], 0, $iv_size);
463 460
 
464 461
 				$key_size = mcrypt_enc_get_key_size($mcrypt);
465
-				if (bytes($key) > $key_size) $key = cut_bytes($key,0,$key_size-1);
462
+				if (bytes($key) > $key_size) $key = cut_bytes($key, 0, $key_size - 1);
466 463
 
467 464
 				if (mcrypt_generic_init($mcrypt, $key, $iv) < 0)
468 465
 				{
Please login to merge, or discard this patch.
Braces   +33 added lines, -8 removed lines patch added patch discarded remove patch
@@ -117,7 +117,10 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public static function read($acc_id, $type=null, $account_id=null)
119 119
 	{
120
-		if (is_null($type)) $type = self::ALL;
120
+		if (is_null($type))
121
+		{
122
+			$type = self::ALL;
123
+		}
121 124
 		if (is_null($account_id))
122 125
 		{
123 126
 			$account_id = array(0, $GLOBALS['egw_info']['user']['account_id']);
@@ -250,7 +253,10 @@  discard block
 block discarded – undo
250 253
 		// no need to write empty usernames, but delete existing row
251 254
 		if ((string)$username === '')
252 255
 		{
253
-			if ($cred_id) self::$db->delete(self::TABLE, array('cred_id' => $cred_id), __LINE__, __FILE__, self::APP);
256
+			if ($cred_id)
257
+			{
258
+				self::$db->delete(self::TABLE, array('cred_id' => $cred_id), __LINE__, __FILE__, self::APP);
259
+			}
254 260
 			return;	// nothing to save
255 261
 		}
256 262
 		$pw_enc = self::CLEARTEXT;
@@ -299,9 +305,19 @@  discard block
 block discarded – undo
299 305
 			throw new Api\Exception\WrongParameter(__METHOD__."() no acc_id AND no account_id parameter!");
300 306
 		}
301 307
 		$where = array();
302
-		if ($acc_id > 0) $where['acc_id'] = $acc_id;
303
-		if (isset($account_id)) $where['account_id'] = $account_id;
304
-		if ($type != self::ALL) $where[] = '(cred_type & '.(int)$type.') > 0';	// postgreSQL require > 0, or gives error as it expects boolean
308
+		if ($acc_id > 0)
309
+		{
310
+			$where['acc_id'] = $acc_id;
311
+		}
312
+		if (isset($account_id))
313
+		{
314
+			$where['account_id'] = $account_id;
315
+		}
316
+		if ($type != self::ALL)
317
+		{
318
+			$where[] = '(cred_type & '.(int)$type.') > 0';
319
+		}
320
+		// postgreSQL require > 0, or gives error as it expects boolean
305 321
 
306 322
 		self::$db->delete(self::TABLE, $where, __LINE__, __FILE__, self::APP);
307 323
 
@@ -382,7 +398,10 @@  discard block
 block discarded – undo
382 398
 	 */
383 399
 	static public function changepassword(array $data)
384 400
 	{
385
-		if (empty($data['old_passwd'])) return;
401
+		if (empty($data['old_passwd']))
402
+		{
403
+			return;
404
+		}
386 405
 
387 406
 		$old_mcrypt = null;
388 407
 		foreach(self::$db->select(self::TABLE, self::TABLE.'.*', array(
@@ -393,7 +412,10 @@  discard block
 block discarded – undo
393 412
 			{
394 413
 				$old_mcrypt = self::init_crypt($data['old_passwd']);
395 414
 				$new_mcrypt = self::init_crypt($data['new_passwd']);
396
-				if (!$old_mcrypt && !$new_mcrypt) return;
415
+				if (!$old_mcrypt && !$new_mcrypt)
416
+				{
417
+					return;
418
+				}
397 419
 			}
398 420
 			$password = self::decrypt($row, $old_mcrypt);
399 421
 
@@ -462,7 +484,10 @@  discard block
 block discarded – undo
462 484
 					mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size);
463 485
 
464 486
 				$key_size = mcrypt_enc_get_key_size($mcrypt);
465
-				if (bytes($key) > $key_size) $key = cut_bytes($key,0,$key_size-1);
487
+				if (bytes($key) > $key_size)
488
+				{
489
+					$key = cut_bytes($key,0,$key_size-1);
490
+				}
466 491
 
467 492
 				if (mcrypt_generic_init($mcrypt, $key, $iv) < 0)
468 493
 				{
Please login to merge, or discard this patch.
api/src/Mail/Hooks.php 4 patches
Doc Comments   -8 removed lines patch added patch discarded remove patch
@@ -36,9 +36,6 @@  discard block
 block discarded – undo
36 36
      * Hook called before an account get deleted
37 37
      *
38 38
      * @param array $data
39
-     * @param int $data['account_id'] numerical id
40
-     * @param string $data['account_lid'] account-name
41
-     * @param int $data['new_owner'] account-id of new owner, or false if data should get deleted
42 39
      */
43 40
 	static function deleteaccount(array $data)
44 41
 	{
@@ -52,8 +49,6 @@  discard block
 block discarded – undo
52 49
      * Hook called before a group get deleted
53 50
      *
54 51
      * @param array $data
55
-     * @param int $data['account_id'] numerical id
56
-     * @param string $data['account_name'] account-name
57 52
      */
58 53
 	static function deletegroup(array $data)
59 54
 	{
@@ -64,9 +59,6 @@  discard block
 block discarded – undo
64 59
      * Hook called when an account get added or edited
65 60
      *
66 61
      * @param array $data
67
-     * @param int $data['account_id'] numerical id
68
-     * @param string $data['account_lid'] account-name
69
-     * @param string $data['account_email'] email
70 62
 	 */
71 63
 	static function addaccount(array $data)
72 64
 	{
Please login to merge, or discard this patch.
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
 		}
33 33
 	}
34 34
 
35
-    /**
36
-     * Hook called before an account get deleted
37
-     *
38
-     * @param array $data
39
-     * @param int $data['account_id'] numerical id
40
-     * @param string $data['account_lid'] account-name
41
-     * @param int $data['new_owner'] account-id of new owner, or false if data should get deleted
42
-     */
35
+	/**
36
+	 * Hook called before an account get deleted
37
+	 *
38
+	 * @param array $data
39
+	 * @param int $data['account_id'] numerical id
40
+	 * @param string $data['account_lid'] account-name
41
+	 * @param int $data['new_owner'] account-id of new owner, or false if data should get deleted
42
+	 */
43 43
 	static function deleteaccount(array $data)
44 44
 	{
45 45
 		self::run_plugin_hooks('deleteAccount', $data);
@@ -48,25 +48,25 @@  discard block
 block discarded – undo
48 48
 		Account::delete(0, $data['account_id']);
49 49
 	}
50 50
 
51
-    /**
52
-     * Hook called before a group get deleted
53
-     *
54
-     * @param array $data
55
-     * @param int $data['account_id'] numerical id
56
-     * @param string $data['account_name'] account-name
57
-     */
51
+	/**
52
+	 * Hook called before a group get deleted
53
+	 *
54
+	 * @param array $data
55
+	 * @param int $data['account_id'] numerical id
56
+	 * @param string $data['account_name'] account-name
57
+	 */
58 58
 	static function deletegroup(array $data)
59 59
 	{
60 60
 		Account::delete(0, $data['account_id']);
61 61
 	}
62 62
 
63 63
 	/**
64
-     * Hook called when an account get added or edited
65
-     *
66
-     * @param array $data
67
-     * @param int $data['account_id'] numerical id
68
-     * @param string $data['account_lid'] account-name
69
-     * @param string $data['account_email'] email
64
+	 * Hook called when an account get added or edited
65
+	 *
66
+	 * @param array $data
67
+	 * @param int $data['account_id'] numerical id
68
+	 * @param string $data['account_lid'] account-name
69
+	 * @param string $data['account_email'] email
70 70
 	 */
71 71
 	static function addaccount(array $data)
72 72
 	{
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 	 */
83 83
 	protected static function run_plugin_hooks($method, array $data)
84 84
 	{
85
-		foreach(Account::search((int)$data['account_id'], 'params') as $params)
85
+		foreach (Account::search((int)$data['account_id'], 'params') as $params)
86 86
 		{
87
-			if (!Account::is_multiple($params)) continue;	// no need to waste time on personal accounts
87
+			if (!Account::is_multiple($params)) continue; // no need to waste time on personal accounts
88 88
 
89 89
 			try {
90 90
 				$account = new Account($params);
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 					$imap->$method($data);
101 101
 				}
102 102
 			}
103
-			catch(\Exception $e) {
103
+			catch (\Exception $e) {
104 104
 				_egw_log_exception($e);
105 105
 				// ignore exception, without stalling other hooks
106 106
 			}
Please login to merge, or discard this patch.
Braces   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,11 @@
 block discarded – undo
84 84
 	{
85 85
 		foreach(Account::search((int)$data['account_id'], 'params') as $params)
86 86
 		{
87
-			if (!Account::is_multiple($params)) continue;	// no need to waste time on personal accounts
87
+			if (!Account::is_multiple($params))
88
+			{
89
+				continue;
90
+			}
91
+			// no need to waste time on personal accounts
88 92
 
89 93
 			try {
90 94
 				$account = new Account($params);
Please login to merge, or discard this patch.