@@ -200,7 +200,10 @@ discard block |
||
| 200 | 200 | public static function getInstance($_restoreSession=true, &$_profileID=0, $_validate=true, $_oldImapServerObject=false, $_reuseCache=null) |
| 201 | 201 | { |
| 202 | 202 | //$_restoreSession=false; |
| 203 | - if (is_null($_reuseCache)) $_reuseCache = $_restoreSession; |
|
| 203 | + if (is_null($_reuseCache)) |
|
| 204 | + { |
|
| 205 | + $_reuseCache = $_restoreSession; |
|
| 206 | + } |
|
| 204 | 207 | //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()); |
| 205 | 208 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($_oldImapServerObject)); |
| 206 | 209 | self::$profileDefunct = Cache::getCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),5*1); |
@@ -231,9 +234,15 @@ discard block |
||
| 231 | 234 | { |
| 232 | 235 | $profileID = Mail\Account::get_default_acc_id(); |
| 233 | 236 | } |
| 234 | - if ($profileID!=$_profileID) $_restoreSession==false; |
|
| 237 | + if ($profileID!=$_profileID) |
|
| 238 | + { |
|
| 239 | + $_restoreSession==false; |
|
| 240 | + } |
|
| 235 | 241 | $_profileID=$profileID; |
| 236 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace()); |
|
| 242 | + if (self::$debug) |
|
| 243 | + { |
|
| 244 | + error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace()); |
|
| 245 | + } |
|
| 237 | 246 | } |
| 238 | 247 | // no validation or restoreSession for old ImapServer Object, just fetch it and return it |
| 239 | 248 | if ($_oldImapServerObject===true) |
@@ -272,7 +281,8 @@ discard block |
||
| 272 | 281 | // TODO: merge mailprefs into userprefs, for easy treatment |
| 273 | 282 | self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail']; |
| 274 | 283 | self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions']; |
| 275 | - } catch (\Exception $e) |
|
| 284 | + } |
|
| 285 | + catch (\Exception $e) |
|
| 276 | 286 | { |
| 277 | 287 | $newprofileID = Mail\Account::get_default_acc_id(); |
| 278 | 288 | // try loading the default profile for the user |
@@ -290,9 +300,15 @@ discard block |
||
| 290 | 300 | self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate ); |
| 291 | 301 | } |
| 292 | 302 | self::$instances[$_profileID]->profileID = $_profileID; |
| 293 | - if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new Horde_Idna; |
|
| 303 | + if (!isset(self::$instances[$_profileID]->idna2)) |
|
| 304 | + { |
|
| 305 | + self::$instances[$_profileID]->idna2 = new Horde_Idna; |
|
| 306 | + } |
|
| 294 | 307 | //if ($_profileID==0); error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID); |
| 295 | - if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail'); |
|
| 308 | + if (is_null(self::$mailConfig)) |
|
| 309 | + { |
|
| 310 | + self::$mailConfig = Config::read('mail'); |
|
| 311 | + } |
|
| 296 | 312 | return self::$instances[$_profileID]; |
| 297 | 313 | } |
| 298 | 314 | |
@@ -308,7 +324,10 @@ discard block |
||
| 308 | 324 | public static function fixInvalidAliasAddress($refrence, $address) |
| 309 | 325 | { |
| 310 | 326 | $parts = explode('@', $refrence); |
| 311 | - if (!strpos($address,'@') && !empty($parts[1])) $address .= '@'.$parts[1]; |
|
| 327 | + if (!strpos($address,'@') && !empty($parts[1])) |
|
| 328 | + { |
|
| 329 | + $address .= '@'.$parts[1]; |
|
| 330 | + } |
|
| 312 | 331 | return $address; |
| 313 | 332 | } |
| 314 | 333 | |
@@ -333,14 +352,20 @@ discard block |
||
| 333 | 352 | } |
| 334 | 353 | catch (\Exception $e) |
| 335 | 354 | { |
| 336 | - if ($_profileID != Mail\Account::get_default_acc_id()) $_profileID = Mail\Account::get_default_acc_id(); |
|
| 355 | + if ($_profileID != Mail\Account::get_default_acc_id()) |
|
| 356 | + { |
|
| 357 | + $_profileID = Mail\Account::get_default_acc_id(); |
|
| 358 | + } |
|
| 337 | 359 | error_log(__METHOD__.__LINE__.' '.$e->getMessage()); |
| 338 | 360 | return false; |
| 339 | 361 | } |
| 340 | 362 | } |
| 341 | 363 | if ($oldProfileID != $_profileID) |
| 342 | 364 | { |
| 343 | - if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID; |
|
| 365 | + if ($oldProfileID && $_profileID==0) |
|
| 366 | + { |
|
| 367 | + $_profileID = $oldProfileID; |
|
| 368 | + } |
|
| 344 | 369 | $GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user'); |
| 345 | 370 | // save prefs |
| 346 | 371 | $GLOBALS['egw']->preferences->save_repository(true); |
@@ -370,11 +395,17 @@ discard block |
||
| 370 | 395 | { |
| 371 | 396 | return $_acc_id; |
| 372 | 397 | } |
| 373 | - if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!"); |
|
| 398 | + if (self::$debug) |
|
| 399 | + { |
|
| 400 | + error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!"); |
|
| 401 | + } |
|
| 374 | 402 | } |
| 375 | 403 | catch (\Exception $e) { |
| 376 | 404 | unset($e); |
| 377 | - if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT found!"); |
|
| 405 | + if (self::$debug) |
|
| 406 | + { |
|
| 407 | + error_log(__METHOD__."($_acc_id) account NOT found!"); |
|
| 408 | + } |
|
| 378 | 409 | } |
| 379 | 410 | } |
| 380 | 411 | // no account specified or specified account not found or not valid |
@@ -383,11 +414,17 @@ discard block |
||
| 383 | 414 | { |
| 384 | 415 | if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap()) |
| 385 | 416 | { |
| 386 | - if (self::$debug && $_acc_id) error_log(__METHOD__."($_acc_id) using $acc_id instead"); |
|
| 417 | + if (self::$debug && $_acc_id) |
|
| 418 | + { |
|
| 419 | + error_log(__METHOD__."($_acc_id) using $acc_id instead"); |
|
| 420 | + } |
|
| 387 | 421 | return $acc_id; |
| 388 | 422 | } |
| 389 | 423 | } |
| 390 | - if (self::$debug) error_log(__METHOD__."($_acc_id) NO valid account found!"); |
|
| 424 | + if (self::$debug) |
|
| 425 | + { |
|
| 426 | + error_log(__METHOD__."($_acc_id) NO valid account found!"); |
|
| 427 | + } |
|
| 391 | 428 | return 0; |
| 392 | 429 | } |
| 393 | 430 | |
@@ -403,10 +440,19 @@ discard block |
||
| 403 | 440 | */ |
| 404 | 441 | private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null) |
| 405 | 442 | { |
| 406 | - if (is_null($_reuseCache)) $_reuseCache = $_restoreSession; |
|
| 407 | - if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset; |
|
| 443 | + if (is_null($_reuseCache)) |
|
| 444 | + { |
|
| 445 | + $_reuseCache = $_restoreSession; |
|
| 446 | + } |
|
| 447 | + if (!empty($_displayCharset)) |
|
| 448 | + { |
|
| 449 | + self::$displayCharset = $_displayCharset; |
|
| 450 | + } |
|
| 408 | 451 | // not nummeric, we assume we only want an empty class object |
| 409 | - if (!is_numeric($_profileID)) return true; |
|
| 452 | + if (!is_numeric($_profileID)) |
|
| 453 | + { |
|
| 454 | + return true; |
|
| 455 | + } |
|
| 410 | 456 | if ($_restoreSession) |
| 411 | 457 | { |
| 412 | 458 | //error_log(__METHOD__." Session restore ".function_backtrace()); |
@@ -421,7 +467,10 @@ discard block |
||
| 421 | 467 | $firstMessage = $this->sessionData['previewMessage']; |
| 422 | 468 | $this->sessionData = array(); |
| 423 | 469 | } |
| 424 | - if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache); |
|
| 470 | + if (!$_reuseCache) |
|
| 471 | + { |
|
| 472 | + $this->forcePrefReload($_profileID,!$_reuseCache); |
|
| 473 | + } |
|
| 425 | 474 | try |
| 426 | 475 | { |
| 427 | 476 | $this->profileID = self::validateProfileID($_profileID); |
@@ -445,7 +494,10 @@ discard block |
||
| 445 | 494 | $_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId; |
| 446 | 495 | } |
| 447 | 496 | |
| 448 | - if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail'); |
|
| 497 | + if (is_null(self::$mailConfig)) |
|
| 498 | + { |
|
| 499 | + self::$mailConfig = Config::read('mail'); |
|
| 500 | + } |
|
| 449 | 501 | } |
| 450 | 502 | |
| 451 | 503 | /** |
@@ -474,7 +526,10 @@ discard block |
||
| 474 | 526 | // unset the mail_preferences session object, to force the reload/rebuild |
| 475 | 527 | Cache::setSession('mail','mail_preferences',serialize(array())); |
| 476 | 528 | Cache::setSession('emailadmin','session_data',serialize(array())); |
| 477 | - if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id); |
|
| 529 | + if ($_resetFolderObjects) |
|
| 530 | + { |
|
| 531 | + self::resetFolderObjectCache($_profile_id); |
|
| 532 | + } |
|
| 478 | 533 | } |
| 479 | 534 | |
| 480 | 535 | /** |
@@ -484,7 +539,10 @@ discard block |
||
| 484 | 539 | { |
| 485 | 540 | $this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1); |
| 486 | 541 | self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10); |
| 487 | - if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID]; |
|
| 542 | + if (!empty(self::$activeFolderCache[$this->profileID])) |
|
| 543 | + { |
|
| 544 | + $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID]; |
|
| 545 | + } |
|
| 488 | 546 | } |
| 489 | 547 | |
| 490 | 548 | /** |
@@ -493,7 +551,10 @@ discard block |
||
| 493 | 551 | function saveSessionData() |
| 494 | 552 | { |
| 495 | 553 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData))); |
| 496 | - if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox']; |
|
| 554 | + if (!empty($this->sessionData['mailbox'])) |
|
| 555 | + { |
|
| 556 | + self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox']; |
|
| 557 | + } |
|
| 497 | 558 | if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache)) |
| 498 | 559 | { |
| 499 | 560 | Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10); |
@@ -516,8 +577,14 @@ discard block |
||
| 516 | 577 | */ |
| 517 | 578 | static function unsetCachedObjects($_profileID=null) |
| 518 | 579 | { |
| 519 | - if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id(); |
|
| 520 | - if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id']; |
|
| 580 | + if (is_null($_profileID)) |
|
| 581 | + { |
|
| 582 | + $_profileID = Mail\Account::get_default_acc_id(); |
|
| 583 | + } |
|
| 584 | + if (is_array($_profileID) && $_profileID['account_id']) |
|
| 585 | + { |
|
| 586 | + $account_id = $_profileID['account_id']; |
|
| 587 | + } |
|
| 521 | 588 | //error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace()); |
| 522 | 589 | if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false))) |
| 523 | 590 | { |
@@ -550,7 +617,10 @@ discard block |
||
| 550 | 617 | Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1); |
| 551 | 618 | } |
| 552 | 619 | |
| 553 | - if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]); |
|
| 620 | + if (isset(self::$instances[$_profileID])) |
|
| 621 | + { |
|
| 622 | + unset(self::$instances[$_profileID]); |
|
| 623 | + } |
|
| 554 | 624 | } |
| 555 | 625 | if (is_array($_profileID) && $_profileID['location'] == 'clear_cache') |
| 556 | 626 | { |
@@ -579,7 +649,10 @@ discard block |
||
| 579 | 649 | static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null) |
| 580 | 650 | { |
| 581 | 651 | //error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id)); |
| 582 | - if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id']; |
|
| 652 | + if (is_null($account_id)) |
|
| 653 | + { |
|
| 654 | + $account_id = $GLOBALS['egw_info']['user']['account_id']; |
|
| 655 | + } |
|
| 583 | 656 | if (is_array($_ImapServerId)) |
| 584 | 657 | { |
| 585 | 658 | // called via hook |
@@ -618,7 +691,10 @@ discard block |
||
| 618 | 691 | static function resetFolderObjectCache($_ImapServerId=null,$account_id=null) |
| 619 | 692 | { |
| 620 | 693 | //error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace()); |
| 621 | - if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id']; |
|
| 694 | + if (is_null($account_id)) |
|
| 695 | + { |
|
| 696 | + $account_id = $GLOBALS['egw_info']['user']['account_id']; |
|
| 697 | + } |
|
| 622 | 698 | // on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId |
| 623 | 699 | // or treat it as not given. we try that path |
| 624 | 700 | if (is_null($_ImapServerId)||is_array($_ImapServerId)) |
@@ -692,10 +768,14 @@ discard block |
||
| 692 | 768 | |
| 693 | 769 | $userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']); |
| 694 | 770 | |
| 695 | - foreach($identities as $ik => $ident) { |
|
| 771 | + foreach($identities as $ik => $ident) |
|
| 772 | + { |
|
| 696 | 773 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident)); |
| 697 | 774 | $identity = Mail\Account::read_identity($ik); |
| 698 | - if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname']; |
|
| 775 | + if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) |
|
| 776 | + { |
|
| 777 | + $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname']; |
|
| 778 | + } |
|
| 699 | 779 | } |
| 700 | 780 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses)); |
| 701 | 781 | return $userEMailAdresses; |
@@ -713,13 +793,20 @@ discard block |
||
| 713 | 793 | foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name) |
| 714 | 794 | { |
| 715 | 795 | $acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null)); |
| 716 | - 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']); |
|
| 796 | + if (!$resolve_placeholders) |
|
| 797 | + { |
|
| 798 | + $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']); |
|
| 799 | + } |
|
| 717 | 800 | |
| 718 | - foreach(Mail\Account::identities($acc) as $ik => $ident) { |
|
| 801 | + foreach(Mail\Account::identities($acc) as $ik => $ident) |
|
| 802 | + { |
|
| 719 | 803 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident)); |
| 720 | 804 | $identity = Mail\Account::read_identity($ik,$resolve_placeholders); |
| 721 | 805 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity)); |
| 722 | - 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']); |
|
| 806 | + if (!isset($userEMailAdresses[$identity['ident_id']])) |
|
| 807 | + { |
|
| 808 | + $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']); |
|
| 809 | + } |
|
| 723 | 810 | } |
| 724 | 811 | } |
| 725 | 812 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses)); |
@@ -739,12 +826,16 @@ discard block |
||
| 739 | 826 | $account = Mail\Account::read($account); |
| 740 | 827 | } |
| 741 | 828 | $userEMailAdresses = array(); |
| 742 | - foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) { |
|
| 829 | + foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) |
|
| 830 | + { |
|
| 743 | 831 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident)); |
| 744 | 832 | $identity = Mail\Account::read_identity($ik,true,null,$account); |
| 745 | 833 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity)); |
| 746 | 834 | // standardIdentity has ident_id==acc_id (as it is done within account->identities) |
| 747 | - if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id']; |
|
| 835 | + if (empty($identity['ident_id'])) |
|
| 836 | + { |
|
| 837 | + $identity['ident_id'] = $identity['acc_id']; |
|
| 838 | + } |
|
| 748 | 839 | if (!isset($userEMailAdresses[$identity['ident_id']])) |
| 749 | 840 | { |
| 750 | 841 | $userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$identity['acc_id'], |
@@ -787,15 +878,25 @@ discard block |
||
| 787 | 878 | // account select box |
| 788 | 879 | $selectedID = $this->profileID; |
| 789 | 880 | $allAccountData = Mail\Account::search($only_current_user=true, false, null); |
| 790 | - if ($allAccountData) { |
|
| 881 | + if ($allAccountData) |
|
| 882 | + { |
|
| 791 | 883 | $rememberFirst=$selectedFound=null; |
| 792 | 884 | foreach ($allAccountData as $tmpkey => $icServers) |
| 793 | 885 | { |
| 794 | - if (is_null($rememberFirst)) $rememberFirst = $tmpkey; |
|
| 795 | - if ($tmpkey == $selectedID) $selectedFound=true; |
|
| 886 | + if (is_null($rememberFirst)) |
|
| 887 | + { |
|
| 888 | + $rememberFirst = $tmpkey; |
|
| 889 | + } |
|
| 890 | + if ($tmpkey == $selectedID) |
|
| 891 | + { |
|
| 892 | + $selectedFound=true; |
|
| 893 | + } |
|
| 796 | 894 | //error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host)); |
| 797 | 895 | $host = $icServers->acc_imap_host; |
| 798 | - if (empty($host)) continue; |
|
| 896 | + if (empty($host)) |
|
| 897 | + { |
|
| 898 | + continue; |
|
| 899 | + } |
|
| 799 | 900 | $identities[$icServers->acc_id] = $icServers['ident_realname'].' '.$icServers['ident_org'].' <'.$icServers['ident_email'].'>'; |
| 800 | 901 | //error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id])); |
| 801 | 902 | } |
@@ -855,7 +956,10 @@ discard block |
||
| 855 | 956 | */ |
| 856 | 957 | function reopen($_foldername) |
| 857 | 958 | { |
| 858 | - if (self::$debugTimes) $starttime = microtime (true); |
|
| 959 | + if (self::$debugTimes) |
|
| 960 | + { |
|
| 961 | + $starttime = microtime (true); |
|
| 962 | + } |
|
| 859 | 963 | |
| 860 | 964 | //error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace()); |
| 861 | 965 | // TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of |
@@ -865,12 +969,16 @@ discard block |
||
| 865 | 969 | //{ |
| 866 | 970 | //error_log( __METHOD__.' ('.__LINE__.') '." $_foldername ".function_backtrace()); |
| 867 | 971 | //error_log(__METHOD__.' ('.__LINE__.') '.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true)); |
| 868 | - if ($this->folderIsSelectable($_foldername)) { |
|
| 972 | + if ($this->folderIsSelectable($_foldername)) |
|
| 973 | + { |
|
| 869 | 974 | $this->icServer->openMailbox($_foldername); |
| 870 | 975 | } |
| 871 | 976 | $folderOpened = $_foldername; |
| 872 | 977 | //} |
| 873 | - if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') '); |
|
| 978 | + if (self::$debugTimes) |
|
| 979 | + { |
|
| 980 | + self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') '); |
|
| 981 | + } |
|
| 874 | 982 | } |
| 875 | 983 | |
| 876 | 984 | |
@@ -885,13 +993,22 @@ discard block |
||
| 885 | 993 | { |
| 886 | 994 | //error_log( "-------------------------->open connection ".function_backtrace()); |
| 887 | 995 | //error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer)); |
| 888 | - if (self::$debugTimes) $starttime = microtime (true); |
|
| 996 | + if (self::$debugTimes) |
|
| 997 | + { |
|
| 998 | + $starttime = microtime (true); |
|
| 999 | + } |
|
| 889 | 1000 | $mailbox=null; |
| 890 | 1001 | try |
| 891 | 1002 | { |
| 892 | - if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox']; |
|
| 893 | - if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox(); |
|
| 894 | -/* |
|
| 1003 | + if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) |
|
| 1004 | + { |
|
| 1005 | + $mailbox = $this->sessionData['mailbox']; |
|
| 1006 | + } |
|
| 1007 | + if (empty($mailbox)) |
|
| 1008 | + { |
|
| 1009 | + $mailbox = $this->icServer->getCurrentMailbox(); |
|
| 1010 | + } |
|
| 1011 | + /* |
|
| 895 | 1012 | if (isset(Mail\Imap::$supports_keywords[$_icServerID])) |
| 896 | 1013 | { |
| 897 | 1014 | $this->icServer->openMailbox($mailbox); |
@@ -916,7 +1033,10 @@ discard block |
||
| 916 | 1033 | error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage()); |
| 917 | 1034 | throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage()); |
| 918 | 1035 | } |
| 919 | - if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') '); |
|
| 1036 | + if (self::$debugTimes) |
|
| 1037 | + { |
|
| 1038 | + self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') '); |
|
| 1039 | + } |
|
| 920 | 1040 | } |
| 921 | 1041 | |
| 922 | 1042 | /** |
@@ -928,7 +1048,10 @@ discard block |
||
| 928 | 1048 | function getQuotaRoot() |
| 929 | 1049 | { |
| 930 | 1050 | static $quota; |
| 931 | - if (isset($quota)) return $quota; |
|
| 1051 | + if (isset($quota)) |
|
| 1052 | + { |
|
| 1053 | + return $quota; |
|
| 1054 | + } |
|
| 932 | 1055 | if (isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID])) |
| 933 | 1056 | { |
| 934 | 1057 | // something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request |
@@ -937,7 +1060,8 @@ discard block |
||
| 937 | 1060 | try |
| 938 | 1061 | { |
| 939 | 1062 | $this->icServer->getCurrentMailbox(); |
| 940 | - if(!$this->icServer->hasCapability('QUOTA')) { |
|
| 1063 | + if(!$this->icServer->hasCapability('QUOTA')) |
|
| 1064 | + { |
|
| 941 | 1065 | $quota = false; |
| 942 | 1066 | return false; |
| 943 | 1067 | } |
@@ -955,12 +1079,15 @@ discard block |
||
| 955 | 1079 | } |
| 956 | 1080 | } |
| 957 | 1081 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota)); |
| 958 | - if(is_array($quota)) { |
|
| 1082 | + if(is_array($quota)) |
|
| 1083 | + { |
|
| 959 | 1084 | $quota = array( |
| 960 | 1085 | 'usage' => $quota['USED'], |
| 961 | 1086 | 'limit' => $quota['QMAX'], |
| 962 | 1087 | ); |
| 963 | - } else { |
|
| 1088 | + } |
|
| 1089 | + else |
|
| 1090 | + { |
|
| 964 | 1091 | $quota = false; |
| 965 | 1092 | } |
| 966 | 1093 | return $quota; |
@@ -976,7 +1103,11 @@ discard block |
||
| 976 | 1103 | static function getTimeOut($_use='IMAP') |
| 977 | 1104 | { |
| 978 | 1105 | $timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout']; |
| 979 | - if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value |
|
| 1106 | + if (empty($timeout)) |
|
| 1107 | + { |
|
| 1108 | + $timeout = ($_use=='SIEVE'?10:20); |
|
| 1109 | + } |
|
| 1110 | + // this is the default value |
|
| 980 | 1111 | return $timeout; |
| 981 | 1112 | } |
| 982 | 1113 | |
@@ -994,9 +1125,13 @@ discard block |
||
| 994 | 1125 | $foldersNameSpace = array(); |
| 995 | 1126 | $delimiter = $this->getHierarchyDelimiter(); |
| 996 | 1127 | // TODO: cache by $this->icServer->ImapServerId |
| 997 | - if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray(); |
|
| 1128 | + if (is_null($nameSpace)) |
|
| 1129 | + { |
|
| 1130 | + $nameSpace = $this->icServer->getNameSpaceArray(); |
|
| 1131 | + } |
|
| 998 | 1132 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace)); |
| 999 | - if (is_array($nameSpace)) { |
|
| 1133 | + if (is_array($nameSpace)) |
|
| 1134 | + { |
|
| 1000 | 1135 | foreach($nameSpace as $type => $singleNameSpaceArray) |
| 1001 | 1136 | { |
| 1002 | 1137 | foreach ($singleNameSpaceArray as $singleNameSpace) |
@@ -1013,7 +1148,9 @@ discard block |
||
| 1013 | 1148 | $_foldersNameSpace['prefix_present'] = 'forced'; |
| 1014 | 1149 | // uw-imap server with mailbox prefix or dovecot maybe |
| 1015 | 1150 | $_foldersNameSpace['prefix'] = 'mail'; |
| 1016 | - } else { |
|
| 1151 | + } |
|
| 1152 | + else |
|
| 1153 | + { |
|
| 1017 | 1154 | $_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']); |
| 1018 | 1155 | $_foldersNameSpace['prefix'] = $singleNameSpace['name']; |
| 1019 | 1156 | } |
@@ -1040,7 +1177,10 @@ discard block |
||
| 1040 | 1177 | foreach($nameSpace as &$singleNameSpace) |
| 1041 | 1178 | { |
| 1042 | 1179 | //if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix']; |
| 1043 | - if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix']; |
|
| 1180 | + if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) |
|
| 1181 | + { |
|
| 1182 | + return $singleNameSpace['prefix']; |
|
| 1183 | + } |
|
| 1044 | 1184 | } |
| 1045 | 1185 | return ""; |
| 1046 | 1186 | } |
@@ -1054,8 +1194,14 @@ discard block |
||
| 1054 | 1194 | function getHierarchyDelimiter($_useCache=true) |
| 1055 | 1195 | { |
| 1056 | 1196 | static $HierarchyDelimiter = null; |
| 1057 | - if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5); |
|
| 1058 | - if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]); |
|
| 1197 | + if (is_null($HierarchyDelimiter)) |
|
| 1198 | + { |
|
| 1199 | + $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5); |
|
| 1200 | + } |
|
| 1201 | + if ($_useCache===false) |
|
| 1202 | + { |
|
| 1203 | + unset($HierarchyDelimiter[$this->icServer->ImapServerId]); |
|
| 1204 | + } |
|
| 1059 | 1205 | if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId])) |
| 1060 | 1206 | { |
| 1061 | 1207 | return $HierarchyDelimiter[$this->icServer->ImapServerId]; |
@@ -1089,14 +1235,19 @@ discard block |
||
| 1089 | 1235 | { |
| 1090 | 1236 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected); |
| 1091 | 1237 | static $_specialUseFolders = null; |
| 1092 | - 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); |
|
| 1238 | + if (is_null($_specialUseFolders)||empty($_specialUseFolders)) |
|
| 1239 | + { |
|
| 1240 | + $_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5); |
|
| 1241 | + } |
|
| 1093 | 1242 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash)); |
| 1094 | 1243 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent)); |
| 1095 | 1244 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft)); |
| 1096 | 1245 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_template)); |
| 1097 | 1246 | self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId]; |
| 1098 | 1247 | if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId])) |
| 1099 | - return $_specialUseFolders[$this->icServer->ImapServerId]; |
|
| 1248 | + { |
|
| 1249 | + return $_specialUseFolders[$this->icServer->ImapServerId]; |
|
| 1250 | + } |
|
| 1100 | 1251 | $_specialUseFolders[$this->icServer->ImapServerId]=array(); |
| 1101 | 1252 | //if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash])) |
| 1102 | 1253 | $_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash'; |
@@ -1124,7 +1275,8 @@ discard block |
||
| 1124 | 1275 | function folderIsSelectable($folderToSelect) |
| 1125 | 1276 | { |
| 1126 | 1277 | $retval = true; |
| 1127 | - if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) { |
|
| 1278 | + if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) |
|
| 1279 | + { |
|
| 1128 | 1280 | if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false) |
| 1129 | 1281 | { |
| 1130 | 1282 | $retval = false; |
@@ -1177,7 +1329,10 @@ discard block |
||
| 1177 | 1329 | */ |
| 1178 | 1330 | function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true) |
| 1179 | 1331 | { |
| 1180 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly"); |
|
| 1332 | + if (self::$debug) |
|
| 1333 | + { |
|
| 1334 | + error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly"); |
|
| 1335 | + } |
|
| 1181 | 1336 | if (!is_string($_folderName) || empty($_folderName)||(isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID]))) |
| 1182 | 1337 | { |
| 1183 | 1338 | // something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request |
@@ -1189,7 +1344,10 @@ discard block |
||
| 1189 | 1344 | { |
| 1190 | 1345 | $folderInfoCache = $folderBasicInfo[$this->profileID]; |
| 1191 | 1346 | } |
| 1192 | - if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName]; |
|
| 1347 | + if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) |
|
| 1348 | + { |
|
| 1349 | + return $folderInfoCache[$_folderName]; |
|
| 1350 | + } |
|
| 1193 | 1351 | $retValue = array(); |
| 1194 | 1352 | $retValue['subscribed'] = false; |
| 1195 | 1353 | /* |
@@ -1218,7 +1376,10 @@ discard block |
||
| 1218 | 1376 | if (is_array($ret)) |
| 1219 | 1377 | { |
| 1220 | 1378 | $retkeys = array_keys($ret); |
| 1221 | - if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]]; |
|
| 1379 | + if ($retkeys[0]==$_folderName) |
|
| 1380 | + { |
|
| 1381 | + $folderInfoCache[$_folderName] = $ret[$retkeys[0]]; |
|
| 1382 | + } |
|
| 1222 | 1383 | } |
| 1223 | 1384 | else |
| 1224 | 1385 | { |
@@ -1227,7 +1388,8 @@ discard block |
||
| 1227 | 1388 | } |
| 1228 | 1389 | $folderInfo = $folderInfoCache[$_folderName]; |
| 1229 | 1390 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace()); |
| 1230 | - if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) { |
|
| 1391 | + if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) |
|
| 1392 | + { |
|
| 1231 | 1393 | try |
| 1232 | 1394 | { |
| 1233 | 1395 | $folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache); |
@@ -1262,7 +1424,8 @@ discard block |
||
| 1262 | 1424 | $retValue['shortName'] = array_pop($shortNameParts); |
| 1263 | 1425 | $retValue['displayName'] = $_folderName; |
| 1264 | 1426 | $retValue['shortDisplayName'] = $retValue['shortName']; |
| 1265 | - if(strtoupper($retValue['shortName']) == 'INBOX') { |
|
| 1427 | + if(strtoupper($retValue['shortName']) == 'INBOX') |
|
| 1428 | + { |
|
| 1266 | 1429 | $retValue['displayName'] = lang('INBOX'); |
| 1267 | 1430 | $retValue['shortDisplayName'] = lang('INBOX'); |
| 1268 | 1431 | } |
@@ -1271,7 +1434,10 @@ discard block |
||
| 1271 | 1434 | { |
| 1272 | 1435 | $retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']); |
| 1273 | 1436 | } |
| 1274 | - if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue; |
|
| 1437 | + if ($folderInfo) |
|
| 1438 | + { |
|
| 1439 | + $folderBasicInfo[$this->profileID][$_folderName]=$retValue; |
|
| 1440 | + } |
|
| 1275 | 1441 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes'])); |
| 1276 | 1442 | if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false)) |
| 1277 | 1443 | { |
@@ -1283,24 +1449,34 @@ discard block |
||
| 1283 | 1449 | static $subscribedFolders = null; |
| 1284 | 1450 | static $nameSpace = null; |
| 1285 | 1451 | static $prefix = null; |
| 1286 | - if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces(); |
|
| 1452 | + if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) |
|
| 1453 | + { |
|
| 1454 | + $nameSpace[$this->profileID] = $this->_getNameSpaces(); |
|
| 1455 | + } |
|
| 1287 | 1456 | if (!empty($nameSpace[$this->profileID])) |
| 1288 | 1457 | { |
| 1289 | 1458 | $nsNoPersonal=array(); |
| 1290 | 1459 | foreach($nameSpace[$this->profileID] as &$ns) |
| 1291 | 1460 | { |
| 1292 | - if ($ns['type']!='personal') $nsNoPersonal[]=$ns; |
|
| 1461 | + if ($ns['type']!='personal') |
|
| 1462 | + { |
|
| 1463 | + $nsNoPersonal[]=$ns; |
|
| 1464 | + } |
|
| 1293 | 1465 | } |
| 1294 | 1466 | $nameSpace[$this->profileID]=$nsNoPersonal; |
| 1295 | 1467 | } |
| 1296 | - if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName); |
|
| 1468 | + if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) |
|
| 1469 | + { |
|
| 1470 | + $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName); |
|
| 1471 | + } |
|
| 1297 | 1472 | |
| 1298 | 1473 | if ($fetchSubscribedInfo && is_null($subscribedFolders) || empty($subscribedFolders[$this->profileID])) |
| 1299 | 1474 | { |
| 1300 | 1475 | $subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes(); |
| 1301 | 1476 | } |
| 1302 | 1477 | |
| 1303 | - if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) { |
|
| 1478 | + if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) |
|
| 1479 | + { |
|
| 1304 | 1480 | $retValue['subscribed'] = true; |
| 1305 | 1481 | } |
| 1306 | 1482 | |
@@ -1319,8 +1495,7 @@ discard block |
||
| 1319 | 1495 | (isset($this->mailPreferences['trustServersUnseenInfo']) && |
| 1320 | 1496 | $this->mailPreferences['trustServersUnseenInfo']==2 && |
| 1321 | 1497 | $prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false) |
| 1322 | - ) |
|
| 1323 | - { |
|
| 1498 | + ) { |
|
| 1324 | 1499 | //error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']); |
| 1325 | 1500 | // we filter for the combined status of unseen and undeleted, as this is what we show in list |
| 1326 | 1501 | try |
@@ -1332,13 +1507,19 @@ discard block |
||
| 1332 | 1507 | } |
| 1333 | 1508 | catch (\Exception $ee) |
| 1334 | 1509 | { |
| 1335 | - if (self::$debug) error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested."); |
|
| 1510 | + if (self::$debug) |
|
| 1511 | + { |
|
| 1512 | + error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested."); |
|
| 1513 | + } |
|
| 1336 | 1514 | } |
| 1337 | 1515 | } |
| 1338 | 1516 | } |
| 1339 | 1517 | catch (\Exception $e) |
| 1340 | 1518 | { |
| 1341 | - if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true)); |
|
| 1519 | + if (self::$debug) |
|
| 1520 | + { |
|
| 1521 | + error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true)); |
|
| 1522 | + } |
|
| 1342 | 1523 | } |
| 1343 | 1524 | |
| 1344 | 1525 | return $retValue; |
@@ -1363,8 +1544,14 @@ discard block |
||
| 1363 | 1544 | function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false) |
| 1364 | 1545 | { |
| 1365 | 1546 | //self::$debug=true; |
| 1366 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace()); |
|
| 1367 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly"); |
|
| 1547 | + if (self::$debug) |
|
| 1548 | + { |
|
| 1549 | + error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace()); |
|
| 1550 | + } |
|
| 1551 | + if (self::$debug) |
|
| 1552 | + { |
|
| 1553 | + error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly"); |
|
| 1554 | + } |
|
| 1368 | 1555 | $reverse = (bool)$_reverse; |
| 1369 | 1556 | // get the list of messages to fetch |
| 1370 | 1557 | $this->reopen($_folderName); |
@@ -1385,21 +1572,34 @@ discard block |
||
| 1385 | 1572 | //$_filter['range'] ="$start:$end"; |
| 1386 | 1573 | //$_filter['range'] ="$_startMessage:*"; |
| 1387 | 1574 | } |
| 1388 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid"); |
|
| 1389 | - if (self::$debug||self::$debugTimes) $starttime = microtime (true); |
|
| 1575 | + if (self::$debug) |
|
| 1576 | + { |
|
| 1577 | + error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid"); |
|
| 1578 | + } |
|
| 1579 | + if (self::$debug||self::$debugTimes) |
|
| 1580 | + { |
|
| 1581 | + $starttime = microtime (true); |
|
| 1582 | + } |
|
| 1390 | 1583 | //see this example below for a 12 week datefilter (since) |
| 1391 | 1584 | //$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12))); |
| 1392 | 1585 | $_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult); |
| 1393 | 1586 | $sortResult = $_sortResult['match']->ids; |
| 1394 | 1587 | //$modseq = $_sortResult['modseq']; |
| 1395 | 1588 | //error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq); |
| 1396 | - if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') '); |
|
| 1589 | + if (self::$debug||self::$debugTimes) |
|
| 1590 | + { |
|
| 1591 | + self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') '); |
|
| 1592 | + } |
|
| 1397 | 1593 | |
| 1398 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult)); |
|
| 1594 | + if (self::$debug) |
|
| 1595 | + { |
|
| 1596 | + error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult)); |
|
| 1597 | + } |
|
| 1399 | 1598 | #$this->icServer->setDebug(false); |
| 1400 | 1599 | #print "</pre>"; |
| 1401 | 1600 | // nothing found |
| 1402 | - if(!is_array($sortResult) || empty($sortResult)) { |
|
| 1601 | + if(!is_array($sortResult) || empty($sortResult)) |
|
| 1602 | + { |
|
| 1403 | 1603 | $retValue = array(); |
| 1404 | 1604 | $retValue['info']['total'] = 0; |
| 1405 | 1605 | $retValue['info']['first'] = 0; |
@@ -1411,7 +1611,8 @@ discard block |
||
| 1411 | 1611 | #_debug_array($sortResult); |
| 1412 | 1612 | #_debug_array(array_slice($sortResult, -5, -2)); |
| 1413 | 1613 | //error_log("REVERSE: $reverse"); |
| 1414 | - if($reverse === true) { |
|
| 1614 | + if($reverse === true) |
|
| 1615 | + { |
|
| 1415 | 1616 | if ($_startMessage<=$total) |
| 1416 | 1617 | { |
| 1417 | 1618 | $startMessage = $_startMessage-1; |
@@ -1423,7 +1624,10 @@ discard block |
||
| 1423 | 1624 | { |
| 1424 | 1625 | $numberOfMessages = $total%$_numberOfMessages; |
| 1425 | 1626 | //$numberOfMessages = abs($_startMessage-$total-1); |
| 1426 | - if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages; |
|
| 1627 | + if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) |
|
| 1628 | + { |
|
| 1629 | + $_numberOfMessages = $numberOfMessages; |
|
| 1630 | + } |
|
| 1427 | 1631 | //error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total); |
| 1428 | 1632 | } |
| 1429 | 1633 | $startMessage=($total-$_numberOfMessages)-1; |
@@ -1437,19 +1641,36 @@ discard block |
||
| 1437 | 1641 | //$retValue['info']['first'] = $startMessage; |
| 1438 | 1642 | //$retValue['info']['last'] = $total; |
| 1439 | 1643 | } |
| 1440 | - if($startMessage > 0) { |
|
| 1441 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult)); |
|
| 1644 | + if($startMessage > 0) |
|
| 1645 | + { |
|
| 1646 | + if (self::$debug) |
|
| 1647 | + { |
|
| 1648 | + error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult)); |
|
| 1649 | + } |
|
| 1442 | 1650 | $sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage); |
| 1443 | - } else { |
|
| 1444 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult)); |
|
| 1651 | + } |
|
| 1652 | + else |
|
| 1653 | + { |
|
| 1654 | + if (self::$debug) |
|
| 1655 | + { |
|
| 1656 | + error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult)); |
|
| 1657 | + } |
|
| 1445 | 1658 | $sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1))); |
| 1446 | 1659 | } |
| 1447 | 1660 | $sortResult = array_reverse($sortResult); |
| 1448 | - } else { |
|
| 1449 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult)); |
|
| 1661 | + } |
|
| 1662 | + else |
|
| 1663 | + { |
|
| 1664 | + if (self::$debug) |
|
| 1665 | + { |
|
| 1666 | + error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult)); |
|
| 1667 | + } |
|
| 1450 | 1668 | $sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages); |
| 1451 | 1669 | } |
| 1452 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult)); |
|
| 1670 | + if (self::$debug) |
|
| 1671 | + { |
|
| 1672 | + error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult)); |
|
| 1673 | + } |
|
| 1453 | 1674 | } |
| 1454 | 1675 | else |
| 1455 | 1676 | { |
@@ -1458,7 +1679,10 @@ discard block |
||
| 1458 | 1679 | |
| 1459 | 1680 | |
| 1460 | 1681 | // fetch the data for the selected messages |
| 1461 | - if (self::$debug||self::$debugTimes) $starttime = microtime(true); |
|
| 1682 | + if (self::$debug||self::$debugTimes) |
|
| 1683 | + { |
|
| 1684 | + $starttime = microtime(true); |
|
| 1685 | + } |
|
| 1462 | 1686 | try |
| 1463 | 1687 | { |
| 1464 | 1688 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
@@ -1482,7 +1706,10 @@ discard block |
||
| 1482 | 1706 | $fquery->flags(); |
| 1483 | 1707 | $fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time |
| 1484 | 1708 | // if $_fetchPreviews is activated fetch part of the messages too |
| 1485 | - if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0)); |
|
| 1709 | + if ($_fetchPreviews) |
|
| 1710 | + { |
|
| 1711 | + $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0)); |
|
| 1712 | + } |
|
| 1486 | 1713 | $headersNew = $this->icServer->fetch($_folderName, $fquery, array( |
| 1487 | 1714 | 'ids' => $uidsToFetch, |
| 1488 | 1715 | )); |
@@ -1505,14 +1732,20 @@ discard block |
||
| 1505 | 1732 | |
| 1506 | 1733 | $cnt = 0; |
| 1507 | 1734 | |
| 1508 | - foreach((array)$sortResult as $uid) { |
|
| 1735 | + foreach((array)$sortResult as $uid) |
|
| 1736 | + { |
|
| 1509 | 1737 | $sortOrder[$uid] = $cnt++; |
| 1510 | 1738 | } |
| 1511 | 1739 | |
| 1512 | 1740 | $count = 0; |
| 1513 | - if (is_object($headersNew)) { |
|
| 1514 | - if (self::$debug||self::$debugTimes) $starttime = microtime(true); |
|
| 1515 | - foreach($headersNew->ids() as $id) { |
|
| 1741 | + if (is_object($headersNew)) |
|
| 1742 | + { |
|
| 1743 | + if (self::$debug||self::$debugTimes) |
|
| 1744 | + { |
|
| 1745 | + $starttime = microtime(true); |
|
| 1746 | + } |
|
| 1747 | + foreach($headersNew->ids() as $id) |
|
| 1748 | + { |
|
| 1516 | 1749 | $_headerObject = $headersNew->get($id); |
| 1517 | 1750 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject)); |
| 1518 | 1751 | $headerObject = array(); |
@@ -1525,7 +1758,10 @@ discard block |
||
| 1525 | 1758 | // Get already cached headers, 'fetchHeaders' is a label matchimg above |
| 1526 | 1759 | $headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(); |
| 1527 | 1760 | // Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com |
| 1528 | - if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(); |
|
| 1761 | + if (empty($headerForPrio)) |
|
| 1762 | + { |
|
| 1763 | + $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(); |
|
| 1764 | + } |
|
| 1529 | 1765 | //fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns |
| 1530 | 1766 | //nothing worthwhile (as it does for googlemail accounts, when preview is switched on |
| 1531 | 1767 | if ($_fetchPreviews) |
@@ -1536,12 +1772,16 @@ discard block |
||
| 1536 | 1772 | if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio[''])) |
| 1537 | 1773 | { |
| 1538 | 1774 | $length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL); |
| 1539 | - if ($length===false) $length = strlen($bodyPreview); |
|
| 1775 | + if ($length===false) |
|
| 1776 | + { |
|
| 1777 | + $length = strlen($bodyPreview); |
|
| 1778 | + } |
|
| 1540 | 1779 | $headerForPrio = Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray(); |
| 1541 | 1780 | } |
| 1542 | 1781 | } |
| 1543 | 1782 | $headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER); |
| 1544 | - if (self::$debug) { |
|
| 1783 | + if (self::$debug) |
|
| 1784 | + { |
|
| 1545 | 1785 | 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')); |
| 1546 | 1786 | error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio)); |
| 1547 | 1787 | } |
@@ -1551,11 +1791,16 @@ discard block |
||
| 1551 | 1791 | $total--; |
| 1552 | 1792 | continue; |
| 1553 | 1793 | } |
| 1554 | - if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) { |
|
| 1794 | + if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) |
|
| 1795 | + { |
|
| 1555 | 1796 | $headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO'])); |
| 1556 | - } else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) { |
|
| 1797 | + } |
|
| 1798 | + else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) |
|
| 1799 | + { |
|
| 1557 | 1800 | $headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO'])); |
| 1558 | - } else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) { |
|
| 1801 | + } |
|
| 1802 | + else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) |
|
| 1803 | + { |
|
| 1559 | 1804 | $headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO'])); |
| 1560 | 1805 | } /*else $sent_not = "";*/ |
| 1561 | 1806 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject)); |
@@ -1587,7 +1832,11 @@ discard block |
||
| 1587 | 1832 | $rfcAddr = self::parseAddressList($ad); // does some fixing of known problems too |
| 1588 | 1833 | foreach ($rfcAddr as $_rfcAddr) |
| 1589 | 1834 | { |
| 1590 | - if (!$_rfcAddr->valid) continue; // skip. not a valid address |
|
| 1835 | + if (!$_rfcAddr->valid) |
|
| 1836 | + { |
|
| 1837 | + continue; |
|
| 1838 | + } |
|
| 1839 | + // skip. not a valid address |
|
| 1591 | 1840 | $address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal); |
| 1592 | 1841 | } |
| 1593 | 1842 | } |
@@ -1603,7 +1852,10 @@ discard block |
||
| 1603 | 1852 | { |
| 1604 | 1853 | // $bodyPreview is populated at the beginning of the loop, as it may be |
| 1605 | 1854 | // needed to parse the Headers of the Message |
| 1606 | - if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg(); |
|
| 1855 | + if (empty($bodyPreview)) |
|
| 1856 | + { |
|
| 1857 | + $bodyPreview = $_headerObject->getFullMsg(); |
|
| 1858 | + } |
|
| 1607 | 1859 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview)); |
| 1608 | 1860 | $base = Horde_Mime_Part::parseMessage($bodyPreview); |
| 1609 | 1861 | foreach($base->partIterator() as $part) |
@@ -1616,7 +1868,8 @@ discard block |
||
| 1616 | 1868 | 'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset |
| 1617 | 1869 | )), $charset, 'utf-8'); |
| 1618 | 1870 | $headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews)))); |
| 1619 | - } elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart') |
|
| 1871 | + } |
|
| 1872 | + elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart') |
|
| 1620 | 1873 | { |
| 1621 | 1874 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($part)); |
| 1622 | 1875 | } |
@@ -1632,7 +1885,10 @@ discard block |
||
| 1632 | 1885 | $messageMimeType=''; |
| 1633 | 1886 | foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type) |
| 1634 | 1887 | { |
| 1635 | - if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type; |
|
| 1888 | + if ($mime_id==0 || $messageMimeType==='') |
|
| 1889 | + { |
|
| 1890 | + $messageMimeType = $mime_type; |
|
| 1891 | + } |
|
| 1636 | 1892 | $part = $mailStructureObject->getPart($mime_id); |
| 1637 | 1893 | $partdisposition = $part->getDisposition(); |
| 1638 | 1894 | $partPrimaryType = $part->getPrimaryType(); |
@@ -1642,7 +1898,8 @@ discard block |
||
| 1642 | 1898 | // bodypreview could be found (multipart/....) |
| 1643 | 1899 | if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') && |
| 1644 | 1900 | ((intval($mime_id) === 1) || !$mime_id) && |
| 1645 | - ($partdisposition !== 'attachment')) { |
|
| 1901 | + ($partdisposition !== 'attachment')) |
|
| 1902 | + { |
|
| 1646 | 1903 | $_structure=$part; |
| 1647 | 1904 | $this->fetchPartContents($uid, $_structure, false,true); |
| 1648 | 1905 | $headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews)))); |
@@ -1664,10 +1921,19 @@ discard block |
||
| 1664 | 1921 | if ($mime_type=='message/rfc822') |
| 1665 | 1922 | { |
| 1666 | 1923 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap())); |
| 1667 | - foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;} |
|
| 1924 | + foreach($part->contentTypeMap() as $sub_id => $sub_type) |
|
| 1925 | + { |
|
| 1926 | +if ($sub_id != $mime_id) |
|
| 1927 | + { |
|
| 1928 | + $skipParts[$sub_id] = $sub_type; |
|
| 1929 | + } |
|
| 1930 | + } |
|
| 1668 | 1931 | } |
| 1669 | 1932 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts)); |
| 1670 | - if (array_key_exists($mime_id,$skipParts)) continue; |
|
| 1933 | + if (array_key_exists($mime_id,$skipParts)) |
|
| 1934 | + { |
|
| 1935 | + continue; |
|
| 1936 | + } |
|
| 1671 | 1937 | if ($partdisposition=='attachment' || |
| 1672 | 1938 | ($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs |
| 1673 | 1939 | ($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) || |
@@ -1678,7 +1944,10 @@ discard block |
||
| 1678 | 1944 | $headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid; |
| 1679 | 1945 | $headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid; |
| 1680 | 1946 | $headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id; |
| 1681 | - if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName(); |
|
| 1947 | + if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name'])) |
|
| 1948 | + { |
|
| 1949 | + $headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName(); |
|
| 1950 | + } |
|
| 1682 | 1951 | if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') || |
| 1683 | 1952 | $headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef') |
| 1684 | 1953 | { |
@@ -1692,18 +1961,27 @@ discard block |
||
| 1692 | 1961 | //error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (plain):'.array2string($mailStructureObject->findBody('plain'))); |
| 1693 | 1962 | //error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (html):'.array2string($mailStructureObject->findBody('html'))); |
| 1694 | 1963 | //if($count == 0) error_log(__METHOD__.array2string($headerObject)); |
| 1695 | - if (empty($headerObject['UID'])) continue; |
|
| 1964 | + if (empty($headerObject['UID'])) |
|
| 1965 | + { |
|
| 1966 | + continue; |
|
| 1967 | + } |
|
| 1696 | 1968 | //$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']); |
| 1697 | 1969 | // make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime |
| 1698 | - if(substr($headerObject['DATE'],-2) === 'UT') { |
|
| 1970 | + if(substr($headerObject['DATE'],-2) === 'UT') |
|
| 1971 | + { |
|
| 1699 | 1972 | $headerObject['DATE'] .= 'C'; |
| 1700 | 1973 | } |
| 1701 | - if(substr($headerObject['INTERNALDATE'],-2) === 'UT') { |
|
| 1974 | + if(substr($headerObject['INTERNALDATE'],-2) === 'UT') |
|
| 1975 | + { |
|
| 1702 | 1976 | $headerObject['INTERNALDATE'] .= 'C'; |
| 1703 | 1977 | } |
| 1704 | 1978 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#'); |
| 1705 | 1979 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']); |
| 1706 | - if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;} |
|
| 1980 | + if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) |
|
| 1981 | + { |
|
| 1982 | + foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a; |
|
| 1983 | + } |
|
| 1984 | + } |
|
| 1707 | 1985 | $retValue['header'][$sortOrder[$uid]]['subject'] = $this->decode_subject($headerObject['SUBJECT']); |
| 1708 | 1986 | $retValue['header'][$sortOrder[$uid]]['size'] = $headerObject['SIZE']; |
| 1709 | 1987 | $retValue['header'][$sortOrder[$uid]]['date'] = self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true); |
@@ -1714,25 +1992,35 @@ discard block |
||
| 1714 | 1992 | $retValue['header'][$sortOrder[$uid]]['bodypreview'] = $headerObject['BODYPREVIEW']; |
| 1715 | 1993 | $retValue['header'][$sortOrder[$uid]]['priority'] = ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3); |
| 1716 | 1994 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]])); |
| 1717 | - if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO']; |
|
| 1718 | - if (is_array($headerObject['FLAGS'])) { |
|
| 1995 | + if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) |
|
| 1996 | + { |
|
| 1997 | + $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO']; |
|
| 1998 | + } |
|
| 1999 | + if (is_array($headerObject['FLAGS'])) |
|
| 2000 | + { |
|
| 1719 | 2001 | $retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject)); |
| 1720 | 2002 | } |
| 1721 | 2003 | //error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from'))); |
| 1722 | - if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) { |
|
| 2004 | + if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) |
|
| 2005 | + { |
|
| 1723 | 2006 | $retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true); |
| 1724 | 2007 | } |
| 1725 | - if(is_array($headerObject['REPLY-TO']) && $headerObject['REPLY-TO'][0]) { |
|
| 2008 | + if(is_array($headerObject['REPLY-TO']) && $headerObject['REPLY-TO'][0]) |
|
| 2009 | + { |
|
| 1726 | 2010 | $retValue['header'][$sortOrder[$uid]]['reply_to_address'] = self::decode_header($headerObject['REPLY-TO'][0],true); |
| 1727 | 2011 | } |
| 1728 | - if(is_array($headerObject['TO']) && $headerObject['TO'][0]) { |
|
| 2012 | + if(is_array($headerObject['TO']) && $headerObject['TO'][0]) |
|
| 2013 | + { |
|
| 1729 | 2014 | $retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true); |
| 1730 | 2015 | if (count($headerObject['TO'])>1) |
| 1731 | 2016 | { |
| 1732 | 2017 | $ki=0; |
| 1733 | 2018 | foreach($headerObject['TO'] as $k => $add) |
| 1734 | 2019 | { |
| 1735 | - if ($k==0) continue; |
|
| 2020 | + if ($k==0) |
|
| 2021 | + { |
|
| 2022 | + continue; |
|
| 2023 | + } |
|
| 1736 | 2024 | //error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add)); |
| 1737 | 2025 | $retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true); |
| 1738 | 2026 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki])); |
@@ -1740,7 +2028,8 @@ discard block |
||
| 1740 | 2028 | } |
| 1741 | 2029 | } |
| 1742 | 2030 | } |
| 1743 | - if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) { |
|
| 2031 | + if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) |
|
| 2032 | + { |
|
| 1744 | 2033 | $ki=0; |
| 1745 | 2034 | foreach($headerObject['CC'] as $k => $add) |
| 1746 | 2035 | { |
@@ -1754,27 +2043,41 @@ discard block |
||
| 1754 | 2043 | |
| 1755 | 2044 | $count++; |
| 1756 | 2045 | } |
| 1757 | - if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') '); |
|
| 2046 | + if (self::$debug||self::$debugTimes) |
|
| 2047 | + { |
|
| 2048 | + self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') '); |
|
| 2049 | + } |
|
| 1758 | 2050 | //self::$debug=false; |
| 1759 | 2051 | // sort the messages to the requested displayorder |
| 1760 | - if(is_array($retValue['header'])) { |
|
| 2052 | + if(is_array($retValue['header'])) |
|
| 2053 | + { |
|
| 1761 | 2054 | $countMessages = $total; |
| 1762 | - if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages']; |
|
| 2055 | + if (isset($_filter['range'])) |
|
| 2056 | + { |
|
| 2057 | + $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages']; |
|
| 2058 | + } |
|
| 1763 | 2059 | ksort($retValue['header']); |
| 1764 | 2060 | $retValue['info']['total'] = $total; |
| 1765 | 2061 | //if ($_startMessage>$total) $_startMessage = $total-($count-1); |
| 1766 | 2062 | $retValue['info']['first'] = $_startMessage; |
| 1767 | 2063 | $retValue['info']['last'] = $_startMessage + $count - 1 ; |
| 1768 | 2064 | return $retValue; |
| 1769 | - } else { |
|
| 2065 | + } |
|
| 2066 | + else |
|
| 2067 | + { |
|
| 1770 | 2068 | $retValue = array(); |
| 1771 | 2069 | $retValue['info']['total'] = 0; |
| 1772 | 2070 | $retValue['info']['first'] = 0; |
| 1773 | 2071 | $retValue['info']['last'] = 0; |
| 1774 | 2072 | return $retValue; |
| 1775 | 2073 | } |
| 1776 | - } else { |
|
| 1777 | - if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE)); |
|
| 2074 | + } |
|
| 2075 | + else |
|
| 2076 | + { |
|
| 2077 | + if ($headersNew == null && empty($_thisUIDOnly)) |
|
| 2078 | + { |
|
| 2079 | + error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE)); |
|
| 2080 | + } |
|
| 1778 | 2081 | $retValue = array(); |
| 1779 | 2082 | $retValue['info']['total'] = 0; |
| 1780 | 2083 | $retValue['info']['first'] = 0; |
@@ -1791,7 +2094,10 @@ discard block |
||
| 1791 | 2094 | */ |
| 1792 | 2095 | static function prepareFlagsArray($headerObject) |
| 1793 | 2096 | { |
| 1794 | - if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']); |
|
| 2097 | + if (is_array($headerObject['FLAGS'])) |
|
| 2098 | + { |
|
| 2099 | + $headerFlags = array_map('strtolower',$headerObject['FLAGS']); |
|
| 2100 | + } |
|
| 1795 | 2101 | $retValue = array(); |
| 1796 | 2102 | $retValue['recent'] = in_array('\\recent', $headerFlags); |
| 1797 | 2103 | $retValue['flagged'] = in_array('\\flagged', $headerFlags); |
@@ -1842,26 +2148,45 @@ discard block |
||
| 1842 | 2148 | //error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter)); |
| 1843 | 2149 | $try2useCache = true; |
| 1844 | 2150 | static $eMailListContainsDeletedMessages = null; |
| 1845 | - if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 2151 | + if (is_null($eMailListContainsDeletedMessages)) |
|
| 2152 | + { |
|
| 2153 | + $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 2154 | + } |
|
| 1846 | 2155 | // this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED |
| 1847 | 2156 | if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false))) |
| 1848 | 2157 | { |
| 1849 | - if (self::$debugTimes) $starttime = microtime(true); |
|
| 1850 | - 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); |
|
| 2158 | + if (self::$debugTimes) |
|
| 2159 | + { |
|
| 2160 | + $starttime = microtime(true); |
|
| 2161 | + } |
|
| 2162 | + if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) |
|
| 2163 | + { |
|
| 2164 | + $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 2165 | + } |
|
| 1851 | 2166 | $five=true; |
| 1852 | 2167 | $dReverse=1; |
| 1853 | 2168 | $deletedMessages = $this->getSortedList($_folderName, 0, $dReverse, array('status'=>array('DELETED')),$five,false); |
| 1854 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages)); |
|
| 2169 | + if (self::$debug) |
|
| 2170 | + { |
|
| 2171 | + error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages)); |
|
| 2172 | + } |
|
| 1855 | 2173 | $eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count']; |
| 1856 | 2174 | Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1); |
| 1857 | - 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']); |
|
| 2175 | + if (self::$debugTimes) |
|
| 2176 | + { |
|
| 2177 | + self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') '); |
|
| 2178 | + } |
|
| 2179 | + //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']); |
|
| 1858 | 2180 | } |
| 1859 | 2181 | $try2useCache = false; |
| 1860 | 2182 | //self::$supportsORinQuery[$this->profileID]=true; |
| 1861 | 2183 | if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID])) |
| 1862 | 2184 | { |
| 1863 | 2185 | self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10); |
| 1864 | - if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true; |
|
| 2186 | + if (!isset(self::$supportsORinQuery[$this->profileID])) |
|
| 2187 | + { |
|
| 2188 | + self::$supportsORinQuery[$this->profileID]=true; |
|
| 2189 | + } |
|
| 1865 | 2190 | } |
| 1866 | 2191 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]); |
| 1867 | 2192 | $filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]); |
@@ -1872,15 +2197,26 @@ discard block |
||
| 1872 | 2197 | } |
| 1873 | 2198 | //_debug_array($filter); |
| 1874 | 2199 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability())); |
| 1875 | - if($this->icServer->hasCapability('SORT')) { |
|
| 2200 | + if($this->icServer->hasCapability('SORT')) |
|
| 2201 | + { |
|
| 1876 | 2202 | // when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client |
| 1877 | 2203 | // thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if |
| 1878 | 2204 | // there is no messing with the dates) |
| 1879 | 2205 | //if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE'; |
| 1880 | - if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse"); |
|
| 2206 | + if (self::$debug) |
|
| 2207 | + { |
|
| 2208 | + error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse"); |
|
| 2209 | + } |
|
| 1881 | 2210 | $sortOrder = $this->_getSortString($_sort, $_reverse); |
| 1882 | - if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already |
|
| 1883 | - if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter)); |
|
| 2211 | + if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) |
|
| 2212 | + { |
|
| 2213 | + $_reverse=false; |
|
| 2214 | + } |
|
| 2215 | + // as we reversed the result already |
|
| 2216 | + if (self::$debug) |
|
| 2217 | + { |
|
| 2218 | + error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter)); |
|
| 2219 | + } |
|
| 1884 | 2220 | try |
| 1885 | 2221 | { |
| 1886 | 2222 | $sortResult = $this->icServer->search($_folderName, $filter, array( |
@@ -1889,7 +2225,10 @@ discard block |
||
| 1889 | 2225 | // Attempt another search without sorting filter if first try failed with |
| 1890 | 2226 | // no result, as may some servers do not coupe well with sort option |
| 1891 | 2227 | // eventhough they claim to support SORT capability. |
| 1892 | - if (!isset($sortResult['count'])) $sortResult = $this->icServer->search($_folderName, $filter); |
|
| 2228 | + if (!isset($sortResult['count'])) |
|
| 2229 | + { |
|
| 2230 | + $sortResult = $this->icServer->search($_folderName, $filter); |
|
| 2231 | + } |
|
| 1893 | 2232 | |
| 1894 | 2233 | // if there is an Error, we assume that the server is not capable of sorting |
| 1895 | 2234 | } |
@@ -1898,7 +2237,10 @@ discard block |
||
| 1898 | 2237 | //error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage()); |
| 1899 | 2238 | $resultByUid = false; |
| 1900 | 2239 | $sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE); |
| 1901 | - if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE); |
|
| 2240 | + if ($_reverse) |
|
| 2241 | + { |
|
| 2242 | + array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE); |
|
| 2243 | + } |
|
| 1902 | 2244 | try |
| 1903 | 2245 | { |
| 1904 | 2246 | $sortResult = $this->icServer->search($_folderName, $filter, array( |
@@ -1910,9 +2252,17 @@ discard block |
||
| 1910 | 2252 | $sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult']; |
| 1911 | 2253 | } |
| 1912 | 2254 | } |
| 1913 | - if (self::$debug) error_log(__METHOD__.print_r($sortResult,true)); |
|
| 1914 | - } else { |
|
| 1915 | - if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability"); |
|
| 2255 | + if (self::$debug) |
|
| 2256 | + { |
|
| 2257 | + error_log(__METHOD__.print_r($sortResult,true)); |
|
| 2258 | + } |
|
| 2259 | + } |
|
| 2260 | + else |
|
| 2261 | + { |
|
| 2262 | + if (self::$debug) |
|
| 2263 | + { |
|
| 2264 | + error_log(__METHOD__." Mailserver has NO SORT Capability"); |
|
| 2265 | + } |
|
| 1916 | 2266 | //$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE); |
| 1917 | 2267 | //if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE); |
| 1918 | 2268 | try |
@@ -1926,7 +2276,10 @@ discard block |
||
| 1926 | 2276 | // possible error OR Query. But Horde gives no detailed Info :-( |
| 1927 | 2277 | self::$supportsORinQuery[$this->profileID]=false; |
| 1928 | 2278 | Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10); |
| 1929 | - if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message); |
|
| 2279 | + if (self::$debug) |
|
| 2280 | + { |
|
| 2281 | + error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message); |
|
| 2282 | + } |
|
| 1930 | 2283 | $filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]); |
| 1931 | 2284 | try |
| 1932 | 2285 | { |
@@ -1937,11 +2290,15 @@ discard block |
||
| 1937 | 2290 | { |
| 1938 | 2291 | } |
| 1939 | 2292 | } |
| 1940 | - if(is_array($sortResult['match'])) { |
|
| 2293 | + if(is_array($sortResult['match'])) |
|
| 2294 | + { |
|
| 1941 | 2295 | // not sure that this is going so succeed as $sortResult['match'] is a hordeObject |
| 1942 | 2296 | sort($sortResult['match'], SORT_NUMERIC); |
| 1943 | 2297 | } |
| 1944 | - if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true)); |
|
| 2298 | + if (self::$debug) |
|
| 2299 | + { |
|
| 2300 | + error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true)); |
|
| 2301 | + } |
|
| 1945 | 2302 | } |
| 1946 | 2303 | if ($setSession) |
| 1947 | 2304 | { |
@@ -1970,7 +2327,8 @@ discard block |
||
| 1970 | 2327 | $_reverse=false; |
| 1971 | 2328 | if (is_numeric($_sort)) |
| 1972 | 2329 | { |
| 1973 | - switch($_sort) { |
|
| 2330 | + switch($_sort) |
|
| 2331 | + { |
|
| 1974 | 2332 | case 2: |
| 1975 | 2333 | $retValue = array(Horde_Imap_Client::SORT_FROM); |
| 1976 | 2334 | break; |
@@ -1992,7 +2350,8 @@ discard block |
||
| 1992 | 2350 | } |
| 1993 | 2351 | else |
| 1994 | 2352 | { |
| 1995 | - switch(strtoupper($_sort)) { |
|
| 2353 | + switch(strtoupper($_sort)) |
|
| 2354 | + { |
|
| 1996 | 2355 | case 'FROMADDRESS': |
| 1997 | 2356 | $retValue = array(Horde_Imap_Client::SORT_FROM); |
| 1998 | 2357 | break; |
@@ -2018,7 +2377,10 @@ discard block |
||
| 2018 | 2377 | break; |
| 2019 | 2378 | } |
| 2020 | 2379 | } |
| 2021 | - if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE); |
|
| 2380 | + if ($_reverse) |
|
| 2381 | + { |
|
| 2382 | + array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE); |
|
| 2383 | + } |
|
| 2022 | 2384 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue); |
| 2023 | 2385 | return $retValue; |
| 2024 | 2386 | } |
@@ -2037,7 +2399,10 @@ discard block |
||
| 2037 | 2399 | $imapFilter->charset('UTF-8'); |
| 2038 | 2400 | |
| 2039 | 2401 | //_debug_array($_criterias); |
| 2040 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias))); |
|
| 2402 | + if (self::$debug) |
|
| 2403 | + { |
|
| 2404 | + error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias))); |
|
| 2405 | + } |
|
| 2041 | 2406 | if((!is_array($_criterias) || $_criterias['status']=='any') && |
| 2042 | 2407 | (!isset($_criterias['string']) || empty($_criterias['string'])) && |
| 2043 | 2408 | (!isset($_criterias['range'])|| empty($_criterias['range']) || |
@@ -2052,11 +2417,13 @@ discard block |
||
| 2052 | 2417 | // statusQuery MUST be placed first, as search for subject/mailbody and such is |
| 2053 | 2418 | // depending on charset. flagSearch is not BUT messes the charset if called afterwards |
| 2054 | 2419 | $statusQueryValid = false; |
| 2055 | - foreach((array)$_criterias['status'] as $k => $criteria) { |
|
| 2420 | + foreach((array)$_criterias['status'] as $k => $criteria) |
|
| 2421 | + { |
|
| 2056 | 2422 | $imapStatusFilter = new Horde_Imap_Client_Search_Query(); |
| 2057 | 2423 | $imapStatusFilter->charset('UTF-8'); |
| 2058 | 2424 | $criteria = strtoupper($criteria); |
| 2059 | - switch ($criteria) { |
|
| 2425 | + switch ($criteria) |
|
| 2426 | + { |
|
| 2060 | 2427 | case 'ANSWERED': |
| 2061 | 2428 | case 'DELETED': |
| 2062 | 2429 | case 'FLAGGED': |
@@ -2139,9 +2506,11 @@ discard block |
||
| 2139 | 2506 | $imapSearchFilter = new Horde_Imap_Client_Search_Query(); |
| 2140 | 2507 | $imapSearchFilter->charset('UTF-8'); |
| 2141 | 2508 | |
| 2142 | - if(!empty($_criterias['string'])) { |
|
| 2509 | + if(!empty($_criterias['string'])) |
|
| 2510 | + { |
|
| 2143 | 2511 | $criteria = strtoupper($_criterias['type']); |
| 2144 | - switch ($criteria) { |
|
| 2512 | + switch ($criteria) |
|
| 2513 | + { |
|
| 2145 | 2514 | case 'BYDATE': |
| 2146 | 2515 | case 'QUICK': |
| 2147 | 2516 | case 'QUICKWITHCC': |
@@ -2149,9 +2518,12 @@ discard block |
||
| 2149 | 2518 | //$imapSearchFilter->charset('UTF-8'); |
| 2150 | 2519 | $imapFilter2 = new Horde_Imap_Client_Search_Query(); |
| 2151 | 2520 | $imapFilter2->charset('UTF-8'); |
| 2152 | - if($this->isSentFolder($_folder)) { |
|
| 2521 | + if($this->isSentFolder($_folder)) |
|
| 2522 | + { |
|
| 2153 | 2523 | $imapFilter2->headerText('TO', $_criterias['string'], $not=false); |
| 2154 | - } else { |
|
| 2524 | + } |
|
| 2525 | + else |
|
| 2526 | + { |
|
| 2155 | 2527 | $imapFilter2->headerText('FROM', $_criterias['string'], $not=false); |
| 2156 | 2528 | } |
| 2157 | 2529 | if ($_supportsOrInQuery) |
@@ -2182,7 +2554,10 @@ discard block |
||
| 2182 | 2554 | 'GB'=>1024*1000*1000,'G'=>1024*1000*1000, |
| 2183 | 2555 | 'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000); |
| 2184 | 2556 | $numberinBytes=(float)$_criterias['string']; |
| 2185 | - if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit]; |
|
| 2557 | + if (isset($multipleBy[$unit])) |
|
| 2558 | + { |
|
| 2559 | + $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit]; |
|
| 2560 | + } |
|
| 2186 | 2561 | //error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes); |
| 2187 | 2562 | $_criterias['string']=$numberinBytes; |
| 2188 | 2563 | } |
@@ -2219,8 +2594,14 @@ discard block |
||
| 2219 | 2594 | break; |
| 2220 | 2595 | } |
| 2221 | 2596 | } |
| 2222 | - if ($statusQueryValid && !$queryValid) $queryValid=true; |
|
| 2223 | - if ($queryValid) $imapFilter->andSearch($imapSearchFilter); |
|
| 2597 | + if ($statusQueryValid && !$queryValid) |
|
| 2598 | + { |
|
| 2599 | + $queryValid=true; |
|
| 2600 | + } |
|
| 2601 | + if ($queryValid) |
|
| 2602 | + { |
|
| 2603 | + $imapFilter->andSearch($imapSearchFilter); |
|
| 2604 | + } |
|
| 2224 | 2605 | |
| 2225 | 2606 | if (isset($_criterias['range']) && !empty($_criterias['range'])) |
| 2226 | 2607 | { |
@@ -2235,7 +2616,8 @@ discard block |
||
| 2235 | 2616 | unset($_criterias['before']); |
| 2236 | 2617 | $criteria=$_criterias['range']='ON'; |
| 2237 | 2618 | } |
| 2238 | - switch ($criteria) { |
|
| 2619 | + switch ($criteria) |
|
| 2620 | + { |
|
| 2239 | 2621 | case 'BETWEEN': |
| 2240 | 2622 | //try to be smart about missing |
| 2241 | 2623 | //enddate |
@@ -2271,8 +2653,14 @@ discard block |
||
| 2271 | 2653 | $rangeValid = true; |
| 2272 | 2654 | break; |
| 2273 | 2655 | } |
| 2274 | - if ($rangeValid && !$queryValid) $queryValid=true; |
|
| 2275 | - if ($rangeValid) $imapFilter->andSearch($imapRangeFilter); |
|
| 2656 | + if ($rangeValid && !$queryValid) |
|
| 2657 | + { |
|
| 2658 | + $queryValid=true; |
|
| 2659 | + } |
|
| 2660 | + if ($rangeValid) |
|
| 2661 | + { |
|
| 2662 | + $imapFilter->andSearch($imapRangeFilter); |
|
| 2663 | + } |
|
| 2276 | 2664 | } |
| 2277 | 2665 | if (self::$debug) |
| 2278 | 2666 | { |
@@ -2280,10 +2668,13 @@ discard block |
||
| 2280 | 2668 | $query_str = $imapFilter->build(); |
| 2281 | 2669 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias))); |
| 2282 | 2670 | } |
| 2283 | - if($queryValid==false) { |
|
| 2671 | + if($queryValid==false) |
|
| 2672 | + { |
|
| 2284 | 2673 | $imapFilter->flag('DELETED', $set=false); |
| 2285 | 2674 | return $imapFilter; |
| 2286 | - } else { |
|
| 2675 | + } |
|
| 2676 | + else |
|
| 2677 | + { |
|
| 2287 | 2678 | return $imapFilter; |
| 2288 | 2679 | } |
| 2289 | 2680 | } |
@@ -2340,7 +2731,10 @@ discard block |
||
| 2340 | 2731 | } |
| 2341 | 2732 | $stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal); |
| 2342 | 2733 | } |
| 2343 | - if (!empty($stringA)) $_string = implode(',',$stringA); |
|
| 2734 | + if (!empty($stringA)) |
|
| 2735 | + { |
|
| 2736 | + $_string = implode(',',$stringA); |
|
| 2737 | + } |
|
| 2344 | 2738 | } |
| 2345 | 2739 | if ($_tryIDNConversion==='FORCE') |
| 2346 | 2740 | { |
@@ -2365,7 +2759,10 @@ discard block |
||
| 2365 | 2759 | { |
| 2366 | 2760 | return 'No Subject'; |
| 2367 | 2761 | } |
| 2368 | - if ($decode) $_string = self::decode_header($_string); |
|
| 2762 | + if ($decode) |
|
| 2763 | + { |
|
| 2764 | + $_string = self::decode_header($_string); |
|
| 2765 | + } |
|
| 2369 | 2766 | // make sure its utf-8 |
| 2370 | 2767 | $test = @json_encode($_string); |
| 2371 | 2768 | if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0) |
@@ -2403,7 +2800,8 @@ discard block |
||
| 2403 | 2800 | * @param string _parent the parent foldername |
| 2404 | 2801 | * @return ISO-8859-1 / UTF7-IMAP encoded string |
| 2405 | 2802 | */ |
| 2406 | - function _encodeFolderName($_folderName) { |
|
| 2803 | + function _encodeFolderName($_folderName) |
|
| 2804 | + { |
|
| 2407 | 2805 | return Translation::convert($_folderName, self::$displayCharset, 'ISO-8859-1'); |
| 2408 | 2806 | #return Translation::convert($_folderName, self::$displayCharset, 'UTF7-IMAP'); |
| 2409 | 2807 | } |
@@ -2419,21 +2817,36 @@ discard block |
||
| 2419 | 2817 | */ |
| 2420 | 2818 | function createFolder($_parent, $_folderName, &$_error) |
| 2421 | 2819 | { |
| 2422 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace()); |
|
| 2820 | + if (self::$debug) |
|
| 2821 | + { |
|
| 2822 | + error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace()); |
|
| 2823 | + } |
|
| 2423 | 2824 | $parent = $_parent;//$this->_encodeFolderName($_parent); |
| 2424 | 2825 | $folderName = $_folderName;//$this->_encodeFolderName($_folderName); |
| 2425 | 2826 | |
| 2426 | - if(empty($parent)) { |
|
| 2827 | + if(empty($parent)) |
|
| 2828 | + { |
|
| 2427 | 2829 | $newFolderName = $folderName; |
| 2428 | - } else { |
|
| 2830 | + } |
|
| 2831 | + else |
|
| 2832 | + { |
|
| 2429 | 2833 | $HierarchyDelimiter = $this->getHierarchyDelimiter(); |
| 2430 | 2834 | $newFolderName = $parent . $HierarchyDelimiter . $folderName; |
| 2431 | 2835 | } |
| 2432 | - if (empty($newFolderName)) return false; |
|
| 2433 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName); |
|
| 2836 | + if (empty($newFolderName)) |
|
| 2837 | + { |
|
| 2838 | + return false; |
|
| 2839 | + } |
|
| 2840 | + if (self::$debug) |
|
| 2841 | + { |
|
| 2842 | + error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName); |
|
| 2843 | + } |
|
| 2434 | 2844 | if ($this->folderExists($newFolderName,true)) |
| 2435 | 2845 | { |
| 2436 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists."); |
|
| 2846 | + if (self::$debug) |
|
| 2847 | + { |
|
| 2848 | + error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists."); |
|
| 2849 | + } |
|
| 2437 | 2850 | return $newFolderName; |
| 2438 | 2851 | } |
| 2439 | 2852 | try |
@@ -2481,13 +2894,19 @@ discard block |
||
| 2481 | 2894 | $parent = $_parent;//$this->_encodeFolderName($_parent); |
| 2482 | 2895 | $folderName = $_folderName;//$this->_encodeFolderName($_folderName); |
| 2483 | 2896 | |
| 2484 | - if(empty($parent)) { |
|
| 2897 | + if(empty($parent)) |
|
| 2898 | + { |
|
| 2485 | 2899 | $newFolderName = $folderName; |
| 2486 | - } else { |
|
| 2900 | + } |
|
| 2901 | + else |
|
| 2902 | + { |
|
| 2487 | 2903 | $HierarchyDelimiter = $this->getHierarchyDelimiter(); |
| 2488 | 2904 | $newFolderName = $parent . $HierarchyDelimiter . $folderName; |
| 2489 | 2905 | } |
| 2490 | - if (self::$debug) error_log("create folder: $newFolderName"); |
|
| 2906 | + if (self::$debug) |
|
| 2907 | + { |
|
| 2908 | + error_log("create folder: $newFolderName"); |
|
| 2909 | + } |
|
| 2491 | 2910 | try |
| 2492 | 2911 | { |
| 2493 | 2912 | $this->icServer->renameMailbox($oldFolderName, $newFolderName); |
@@ -2561,8 +2980,14 @@ discard block |
||
| 2561 | 2980 | */ |
| 2562 | 2981 | function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true) |
| 2563 | 2982 | { |
| 2564 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible"); |
|
| 2565 | - if (self::$debugTimes) $starttime = microtime (true); |
|
| 2983 | + if (self::$debug) |
|
| 2984 | + { |
|
| 2985 | + error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible"); |
|
| 2986 | + } |
|
| 2987 | + if (self::$debugTimes) |
|
| 2988 | + { |
|
| 2989 | + $starttime = microtime (true); |
|
| 2990 | + } |
|
| 2566 | 2991 | static $folders2return; |
| 2567 | 2992 | //$_subscribedOnly=false; |
| 2568 | 2993 | // always use static on single request if info is available; |
@@ -2570,23 +2995,35 @@ discard block |
||
| 2570 | 2995 | // set $_useCacheIfPossible to false ! |
| 2571 | 2996 | if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId])) |
| 2572 | 2997 | { |
| 2573 | - if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') '); |
|
| 2998 | + if (self::$debugTimes) |
|
| 2999 | + { |
|
| 3000 | + self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') '); |
|
| 3001 | + } |
|
| 2574 | 3002 | return $folders2return[$this->icServer->ImapServerId]; |
| 2575 | 3003 | } |
| 2576 | 3004 | |
| 2577 | 3005 | if ($_subscribedOnly && $_getCounters===false) |
| 2578 | 3006 | { |
| 2579 | - if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 3007 | + if (is_null($folders2return)) |
|
| 3008 | + { |
|
| 3009 | + $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 3010 | + } |
|
| 2580 | 3011 | if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId])) |
| 2581 | 3012 | { |
| 2582 | 3013 | //error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId])); |
| 2583 | - if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') '); |
|
| 3014 | + if (self::$debugTimes) |
|
| 3015 | + { |
|
| 3016 | + self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') '); |
|
| 3017 | + } |
|
| 2584 | 3018 | return $folders2return[$this->icServer->ImapServerId]; |
| 2585 | 3019 | } |
| 2586 | 3020 | } |
| 2587 | 3021 | // use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId] |
| 2588 | 3022 | static $folderBasicInfo; |
| 2589 | - 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); |
|
| 3023 | + if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId])) |
|
| 3024 | + { |
|
| 3025 | + $folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 3026 | + } |
|
| 2590 | 3027 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId]))); |
| 2591 | 3028 | |
| 2592 | 3029 | $delimiter = $this->getHierarchyDelimiter(); |
@@ -2599,7 +3036,8 @@ discard block |
||
| 2599 | 3036 | $inboxData->shortFolderName = 'INBOX'; |
| 2600 | 3037 | $inboxData->shortDisplayName = lang('INBOX'); |
| 2601 | 3038 | $inboxData->subscribed = true; |
| 2602 | - if($_getCounters == true) { |
|
| 3039 | + if($_getCounters == true) |
|
| 3040 | + { |
|
| 2603 | 3041 | $inboxData->counter = $this->getMailBoxCounters('INBOX'); |
| 2604 | 3042 | } |
| 2605 | 3043 | // force unsubscribed by preference showAllFoldersInFolderPane |
@@ -2618,12 +3056,14 @@ discard block |
||
| 2618 | 3056 | //error_log(__METHOD__.__LINE__.array2string($nameSpace)); |
| 2619 | 3057 | if (is_array($nameSpace)) |
| 2620 | 3058 | { |
| 2621 | - foreach($nameSpace as $k => $singleNameSpace) { |
|
| 3059 | + foreach($nameSpace as $k => $singleNameSpace) |
|
| 3060 | + { |
|
| 2622 | 3061 | $type = $singleNameSpace['type']; |
| 2623 | 3062 | // the following line (assumption that for the same namespace the delimiter should be equal) may be wrong |
| 2624 | 3063 | $foldersNameSpace[$type]['delimiter'] = $singleNameSpace['delimiter']; |
| 2625 | 3064 | |
| 2626 | - if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) { |
|
| 3065 | + if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) |
|
| 3066 | + { |
|
| 2627 | 3067 | // fetch and sort the subscribed folders |
| 2628 | 3068 | // we alway fetch the subscribed, as this provides the only way to tell |
| 2629 | 3069 | // if a folder is subscribed or not |
@@ -2674,8 +3114,12 @@ discard block |
||
| 2674 | 3114 | } |
| 2675 | 3115 | } |
| 2676 | 3116 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($foldersNameSpace[$type]['subscribed'])); |
| 2677 | - if (!is_array($foldersNameSpace[$type]['all'])) $foldersNameSpace[$type]['all'] = array(); |
|
| 2678 | - if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) { |
|
| 3117 | + if (!is_array($foldersNameSpace[$type]['all'])) |
|
| 3118 | + { |
|
| 3119 | + $foldersNameSpace[$type]['all'] = array(); |
|
| 3120 | + } |
|
| 3121 | + if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) |
|
| 3122 | + { |
|
| 2679 | 3123 | continue; |
| 2680 | 3124 | } |
| 2681 | 3125 | |
@@ -2705,7 +3149,8 @@ discard block |
||
| 2705 | 3149 | } |
| 2706 | 3150 | |
| 2707 | 3151 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($allMailboxesExt)); |
| 2708 | - foreach ($allMailboxesExt as $mbx) { |
|
| 3152 | + foreach ($allMailboxesExt as $mbx) |
|
| 3153 | + { |
|
| 2709 | 3154 | if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']])) |
| 2710 | 3155 | { |
| 2711 | 3156 | $folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array( |
@@ -2728,20 +3173,33 @@ discard block |
||
| 2728 | 3173 | if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])|| |
| 2729 | 3174 | isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])|| |
| 2730 | 3175 | (substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)])) |
| 2731 | - ) continue; |
|
| 3176 | + ) |
|
| 3177 | + { |
|
| 3178 | + continue; |
|
| 3179 | + } |
|
| 2732 | 3180 | |
| 2733 | 3181 | //echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>"; |
| 2734 | 3182 | $allMailBoxesExtSorted[$mbx['MAILBOX']] = $mbx; |
| 2735 | 3183 | } |
| 2736 | - if (is_array($allMailBoxesExtSorted)) ksort($allMailBoxesExtSorted); |
|
| 3184 | + if (is_array($allMailBoxesExtSorted)) |
|
| 3185 | + { |
|
| 3186 | + ksort($allMailBoxesExtSorted); |
|
| 3187 | + } |
|
| 2737 | 3188 | //_debug_array(array_keys($allMailBoxesExtSorted)); |
| 2738 | 3189 | $allMailboxes = array(); |
| 2739 | - foreach ((array)$allMailBoxesExtSorted as $mbx) { |
|
| 2740 | - if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX']; |
|
| 3190 | + foreach ((array)$allMailBoxesExtSorted as $mbx) |
|
| 3191 | + { |
|
| 3192 | + if (!in_array($mbx['MAILBOX'],$allMailboxes)) |
|
| 3193 | + { |
|
| 3194 | + $allMailboxes[] = $mbx['MAILBOX']; |
|
| 3195 | + } |
|
| 2741 | 3196 | //echo "Result:";_debug_array($allMailboxes); |
| 2742 | 3197 | } |
| 2743 | 3198 | $foldersNameSpace[$type]['all'] = $allMailboxes; |
| 2744 | - if (is_array($foldersNameSpace[$type]['all'])) sort($foldersNameSpace[$type]['all']); |
|
| 3199 | + if (is_array($foldersNameSpace[$type]['all'])) |
|
| 3200 | + { |
|
| 3201 | + sort($foldersNameSpace[$type]['all']); |
|
| 3202 | + } |
|
| 2745 | 3203 | } |
| 2746 | 3204 | } |
| 2747 | 3205 | } |
@@ -2750,24 +3208,50 @@ discard block |
||
| 2750 | 3208 | //echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace); |
| 2751 | 3209 | $autoFolderObjects = $folders = array(); |
| 2752 | 3210 | $autofolder_exists = array(); |
| 2753 | - foreach( array('personal', 'others', 'shared') as $type) { |
|
| 2754 | - if(isset($foldersNameSpace[$type])) { |
|
| 2755 | - if($_subscribedOnly) { |
|
| 2756 | - if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed']; |
|
| 2757 | - } else { |
|
| 2758 | - if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all']; |
|
| 2759 | - } |
|
| 2760 | - foreach((array)$listOfFolders as $folderName) { |
|
| 3211 | + foreach( array('personal', 'others', 'shared') as $type) |
|
| 3212 | + { |
|
| 3213 | + if(isset($foldersNameSpace[$type])) |
|
| 3214 | + { |
|
| 3215 | + if($_subscribedOnly) |
|
| 3216 | + { |
|
| 3217 | + if( !empty($foldersNameSpace[$type]['subscribed']) ) |
|
| 3218 | + { |
|
| 3219 | + $listOfFolders = $foldersNameSpace[$type]['subscribed']; |
|
| 3220 | + } |
|
| 3221 | + } |
|
| 3222 | + else |
|
| 3223 | + { |
|
| 3224 | + if( !empty($foldersNameSpace[$type]['all'])) |
|
| 3225 | + { |
|
| 3226 | + $listOfFolders = $foldersNameSpace[$type]['all']; |
|
| 3227 | + } |
|
| 3228 | + } |
|
| 3229 | + foreach((array)$listOfFolders as $folderName) |
|
| 3230 | + { |
|
| 2761 | 3231 | //echo "<br>FolderToCheck:$folderName<br>"; |
| 2762 | 3232 | //error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName); |
| 2763 | - if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go. |
|
| 2764 | - if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) { |
|
| 3233 | + if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) |
|
| 3234 | + { |
|
| 3235 | + continue; |
|
| 3236 | + } |
|
| 3237 | + //when subscribedonly, we fetch all folders in one go. |
|
| 3238 | + if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) |
|
| 3239 | + { |
|
| 2765 | 3240 | #echo "$folderName failed to be here <br>"; |
| 2766 | 3241 | continue; |
| 2767 | 3242 | } |
| 2768 | - if (isset($folders[$folderName])) continue; |
|
| 2769 | - if (isset($autoFolderObjects[$folderName])) continue; |
|
| 2770 | - if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter']; |
|
| 3243 | + if (isset($folders[$folderName])) |
|
| 3244 | + { |
|
| 3245 | + continue; |
|
| 3246 | + } |
|
| 3247 | + if (isset($autoFolderObjects[$folderName])) |
|
| 3248 | + { |
|
| 3249 | + continue; |
|
| 3250 | + } |
|
| 3251 | + if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) |
|
| 3252 | + { |
|
| 3253 | + $delimiter = $foldersNameSpace[$type]['delimiter']; |
|
| 3254 | + } |
|
| 2771 | 3255 | $folderParts = explode($delimiter, $folderName); |
| 2772 | 3256 | $shortName = array_pop($folderParts); |
| 2773 | 3257 | |
@@ -2775,17 +3259,20 @@ discard block |
||
| 2775 | 3259 | $folderObject->delimiter = $delimiter; |
| 2776 | 3260 | $folderObject->folderName = $folderName; |
| 2777 | 3261 | $folderObject->shortFolderName = $shortName; |
| 2778 | - if(!$_subscribedOnly) { |
|
| 3262 | + if(!$_subscribedOnly) |
|
| 3263 | + { |
|
| 2779 | 3264 | #echo $folderName."->".$type."<br>"; |
| 2780 | 3265 | #_debug_array($foldersNameSpace[$type]['subscribed']); |
| 2781 | 3266 | $folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']); |
| 2782 | 3267 | } |
| 2783 | 3268 | |
| 2784 | - if($_getCounters == true) { |
|
| 3269 | + if($_getCounters == true) |
|
| 3270 | + { |
|
| 2785 | 3271 | //error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName); |
| 2786 | 3272 | $folderObject->counter = $this->getMailBoxCounters($folderName); |
| 2787 | 3273 | } |
| 2788 | - if(strtoupper($folderName) == 'INBOX') { |
|
| 3274 | + if(strtoupper($folderName) == 'INBOX') |
|
| 3275 | + { |
|
| 2789 | 3276 | $folderName = 'INBOX'; |
| 2790 | 3277 | $folderObject->folderName = 'INBOX'; |
| 2791 | 3278 | $folderObject->shortFolderName = 'INBOX'; |
@@ -2793,24 +3280,34 @@ discard block |
||
| 2793 | 3280 | $folderObject->shortDisplayName = lang('INBOX'); |
| 2794 | 3281 | $folderObject->subscribed = true; |
| 2795 | 3282 | // translate the automatic Folders (Sent, Drafts, ...) like the INBOX |
| 2796 | - } elseif (in_array($shortName,self::$autoFolders)) { |
|
| 3283 | + } |
|
| 3284 | + elseif (in_array($shortName,self::$autoFolders)) |
|
| 3285 | + { |
|
| 2797 | 3286 | $tmpfolderparts = explode($delimiter,$folderObject->folderName); |
| 2798 | 3287 | array_pop($tmpfolderparts); |
| 2799 | 3288 | $folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName); |
| 2800 | 3289 | $folderObject->shortDisplayName = lang($shortName); |
| 2801 | 3290 | unset($tmpfolderparts); |
| 2802 | - } else { |
|
| 3291 | + } |
|
| 3292 | + else |
|
| 3293 | + { |
|
| 2803 | 3294 | $folderObject->displayName = $folderObject->folderName; |
| 2804 | 3295 | $folderObject->shortDisplayName = $shortName; |
| 2805 | 3296 | } |
| 2806 | 3297 | //$folderName = $folderName; |
| 2807 | - if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) { |
|
| 3298 | + if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) |
|
| 3299 | + { |
|
| 2808 | 3300 | $autoFolderObjects[$folderName] = $folderObject; |
| 2809 | - } else { |
|
| 3301 | + } |
|
| 3302 | + else |
|
| 3303 | + { |
|
| 2810 | 3304 | $folders[$folderName] = $folderObject; |
| 2811 | 3305 | } |
| 2812 | 3306 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName); |
| 2813 | - if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); |
|
| 3307 | + if (!isset(self::$specialUseFolders)) |
|
| 3308 | + { |
|
| 3309 | + $this->getSpecialUseFolders (); |
|
| 3310 | + } |
|
| 2814 | 3311 | if (isset(self::$specialUseFolders[$folderName])) |
| 2815 | 3312 | { |
| 2816 | 3313 | $autofolder_exists[$folderName] = self::$specialUseFolders[$folderName]; |
@@ -2818,7 +3315,8 @@ discard block |
||
| 2818 | 3315 | } |
| 2819 | 3316 | } |
| 2820 | 3317 | } |
| 2821 | - if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) { |
|
| 3318 | + if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) |
|
| 3319 | + { |
|
| 2822 | 3320 | uasort($autoFolderObjects,array($this,"sortByAutoFolderPos")); |
| 2823 | 3321 | } |
| 2824 | 3322 | // check if some standard folders are missing and need to be created |
@@ -2827,7 +3325,10 @@ discard block |
||
| 2827 | 3325 | // if new folders have been created, re-read folders ignoring the cache |
| 2828 | 3326 | return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false); // false = do NOT use cache |
| 2829 | 3327 | } |
| 2830 | - if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName")); |
|
| 3328 | + if (is_array($folders)) |
|
| 3329 | + { |
|
| 3330 | + uasort($folders,array($this,"sortByDisplayName")); |
|
| 3331 | + } |
|
| 2831 | 3332 | //$folders2return = array_merge($autoFolderObjects,$folders); |
| 2832 | 3333 | //_debug_array($folders2return); #exit; |
| 2833 | 3334 | $folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders); |
@@ -2839,7 +3340,10 @@ discard block |
||
| 2839 | 3340 | Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1); |
| 2840 | 3341 | } |
| 2841 | 3342 | Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1); |
| 2842 | - if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') '); |
|
| 3343 | + if (self::$debugTimes) |
|
| 3344 | + { |
|
| 3345 | + self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') '); |
|
| 3346 | + } |
|
| 2843 | 3347 | return $folders2return[$this->icServer->ImapServerId]; |
| 2844 | 3348 | } |
| 2845 | 3349 | |
@@ -2867,31 +3371,44 @@ discard block |
||
| 2867 | 3371 | |
| 2868 | 3372 | $folders = $nameSpace = array(); |
| 2869 | 3373 | $nameSpaceTmp = $this->_getNameSpaces(); |
| 2870 | - foreach($nameSpaceTmp as $k => $singleNameSpace) { |
|
| 3374 | + foreach($nameSpaceTmp as $k => $singleNameSpace) |
|
| 3375 | + { |
|
| 2871 | 3376 | $nameSpace[$singleNameSpace['type']]=$singleNameSpace; |
| 2872 | 3377 | } |
| 2873 | 3378 | unset($nameSpaceTmp); |
| 2874 | 3379 | |
| 2875 | 3380 | //error_log(__METHOD__.__LINE__.array2string($nameSpace)); |
| 2876 | 3381 | // Get special use folders |
| 2877 | - if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders |
|
| 3382 | + if (!isset(self::$specialUseFolders)) |
|
| 3383 | + { |
|
| 3384 | + $this->getSpecialUseFolders (); |
|
| 3385 | + } |
|
| 3386 | + // Set self::$specialUseFolders |
|
| 2878 | 3387 | // topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace |
| 2879 | - if ($_onlyTopLevel) // top level leaves |
|
| 3388 | + if ($_onlyTopLevel) |
|
| 3389 | + { |
|
| 3390 | + // top level leaves |
|
| 2880 | 3391 | { |
| 2881 | 3392 | // Get top mailboxes of icServer |
| 2882 | 3393 | $topFolders = $this->icServer->getMailboxes("", 2, true); |
| 3394 | + } |
|
| 2883 | 3395 | // Trigger examination of namespace to retrieve |
| 2884 | 3396 | // folders located in other and shared; needed only for some servers |
| 2885 | - if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail'); |
|
| 3397 | + if (is_null(self::$mailConfig)) |
|
| 3398 | + { |
|
| 3399 | + self::$mailConfig = Config::read('mail'); |
|
| 3400 | + } |
|
| 2886 | 3401 | if (self::$mailConfig['examineNamespace']) |
| 2887 | 3402 | { |
| 2888 | 3403 | $prefixes=array(); |
| 2889 | 3404 | if (is_array($nameSpace)) |
| 2890 | 3405 | { |
| 2891 | - foreach($nameSpace as $k => $singleNameSpace) { |
|
| 3406 | + foreach($nameSpace as $k => $singleNameSpace) |
|
| 3407 | + { |
|
| 2892 | 3408 | $type = $singleNameSpace['type']; |
| 2893 | 3409 | |
| 2894 | - if(is_array($singleNameSpace) && $singleNameSpace['prefix']){ |
|
| 3410 | + if(is_array($singleNameSpace) && $singleNameSpace['prefix']) |
|
| 3411 | + { |
|
| 2895 | 3412 | $prefixes[$type] = $singleNameSpace['prefix']; |
| 2896 | 3413 | //regard extra care for nameSpacequeries when configured AND respect $_search |
| 2897 | 3414 | $result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true); |
@@ -2967,7 +3484,10 @@ discard block |
||
| 2967 | 3484 | $nFolders [$path] = $folder; |
| 2968 | 3485 | } |
| 2969 | 3486 | } |
| 2970 | - if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder')); |
|
| 3487 | + if (is_array($aFolders)) |
|
| 3488 | + { |
|
| 3489 | + uasort ($aFolders, array($this,'sortByAutofolder')); |
|
| 3490 | + } |
|
| 2971 | 3491 | //ksort($aFolders); |
| 2972 | 3492 | |
| 2973 | 3493 | // Sort none auto folders base on mailbox name |
@@ -2977,12 +3497,17 @@ discard block |
||
| 2977 | 3497 | } |
| 2978 | 3498 | else |
| 2979 | 3499 | { |
| 2980 | - if (is_array($subFolders)) ksort($subFolders); |
|
| 3500 | + if (is_array($subFolders)) |
|
| 3501 | + { |
|
| 3502 | + ksort($subFolders); |
|
| 3503 | + } |
|
| 2981 | 3504 | } |
| 2982 | 3505 | $folders = array_merge($folders,(array)$mainFolder, (array)$subFolders); |
| 2983 | 3506 | } |
| 2984 | 3507 | } |
| 2985 | - elseif ($_nodePath) // single node |
|
| 3508 | + elseif ($_nodePath) |
|
| 3509 | + { |
|
| 3510 | + // single node |
|
| 2986 | 3511 | { |
| 2987 | 3512 | switch ($_search) |
| 2988 | 3513 | { |
@@ -2990,6 +3515,7 @@ discard block |
||
| 2990 | 3515 | case 0: |
| 2991 | 3516 | case 2: |
| 2992 | 3517 | $path = $_nodePath.''.$delimiter; |
| 3518 | + } |
|
| 2993 | 3519 | break; |
| 2994 | 3520 | // Node itself |
| 2995 | 3521 | // shouldn't contain next level delimiter |
@@ -3008,11 +3534,14 @@ discard block |
||
| 3008 | 3534 | |
| 3009 | 3535 | uasort($folders,array($this,'sortByMailbox'));//ksort($folders); |
| 3010 | 3536 | } |
| 3011 | - elseif(!$_nodePath) // all |
|
| 3537 | + elseif(!$_nodePath) |
|
| 3538 | + { |
|
| 3539 | + // all |
|
| 3012 | 3540 | { |
| 3013 | 3541 | if ($_subscribedOnly) |
| 3014 | 3542 | { |
| 3015 | 3543 | $folders = $this->icServer->listSubscribedMailboxes('', 0, true); |
| 3544 | + } |
|
| 3016 | 3545 | } |
| 3017 | 3546 | else |
| 3018 | 3547 | { |
@@ -3024,7 +3553,10 @@ discard block |
||
| 3024 | 3553 | { |
| 3025 | 3554 | // SORTING FOLDERS |
| 3026 | 3555 | //self::$debugTimes=true; |
| 3027 | - if (self::$debugTimes) $starttime = microtime (true); |
|
| 3556 | + if (self::$debugTimes) |
|
| 3557 | + { |
|
| 3558 | + $starttime = microtime (true); |
|
| 3559 | + } |
|
| 3028 | 3560 | // Merge of all auto folders and specialusefolders |
| 3029 | 3561 | $autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders)))); |
| 3030 | 3562 | uasort($folders,array($this,'sortByMailbox'));//ksort($folders); |
@@ -3034,73 +3566,103 @@ discard block |
||
| 3034 | 3566 | $isGoogleMail=false; |
| 3035 | 3567 | foreach($autoFoldersTmp as $afk=>$aF) |
| 3036 | 3568 | { |
| 3037 | - if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false); |
|
| 3569 | + if (!isset($mySpecialUseFolders[$aF]) && $aF) |
|
| 3570 | + { |
|
| 3571 | + $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false); |
|
| 3572 | + } |
|
| 3038 | 3573 | //error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]); |
| 3039 | 3574 | } |
| 3040 | 3575 | //error_log(array2string($mySpecialUseFolders)); |
| 3041 | - foreach ($tmpFolders as $k => $f) { |
|
| 3576 | + foreach ($tmpFolders as $k => $f) |
|
| 3577 | + { |
|
| 3042 | 3578 | $sorted=false; |
| 3043 | - if (strtoupper(substr($k,0,5))=='INBOX') { |
|
| 3044 | - if (strtoupper($k)=='INBOX') { |
|
| 3579 | + if (strtoupper(substr($k,0,5))=='INBOX') |
|
| 3580 | + { |
|
| 3581 | + if (strtoupper($k)=='INBOX') |
|
| 3582 | + { |
|
| 3045 | 3583 | //error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k); |
| 3046 | 3584 | $inboxFolderObject[$k]=$f; |
| 3047 | 3585 | unset($folders[$k]); |
| 3048 | 3586 | $sorted=true; |
| 3049 | - } else { |
|
| 3587 | + } |
|
| 3588 | + else |
|
| 3589 | + { |
|
| 3050 | 3590 | $isAutoFolder=false; |
| 3051 | 3591 | foreach($autoFoldersTmp as $afk=>$aF) |
| 3052 | 3592 | { |
| 3053 | 3593 | //error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]); |
| 3054 | 3594 | if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/ |
| 3055 | 3595 | ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder |
| 3056 | - stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder |
|
| 3596 | + stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) |
|
| 3597 | + { |
|
| 3598 | + // k is parent of an autofolder |
|
| 3057 | 3599 | { |
| 3058 | 3600 | //error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]); |
| 3059 | 3601 | $isAutoFolder=true; |
| 3602 | + } |
|
| 3060 | 3603 | $autoFolderObjects[$k]=$f; |
| 3061 | 3604 | break; |
| 3062 | 3605 | } |
| 3063 | 3606 | } |
| 3064 | - if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f; |
|
| 3607 | + if ($isAutoFolder==false) |
|
| 3608 | + { |
|
| 3609 | + $inboxSubFolderObjects[$k]=$f; |
|
| 3610 | + } |
|
| 3065 | 3611 | unset($folders[$k]); |
| 3066 | 3612 | $sorted=true; |
| 3067 | 3613 | } |
| 3068 | - } elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') { |
|
| 3614 | + } |
|
| 3615 | + elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') |
|
| 3616 | + { |
|
| 3069 | 3617 | $isGoogleMail=true; |
| 3070 | - if (strtoupper($k)=='[GOOGLE MAIL]') { |
|
| 3618 | + if (strtoupper($k)=='[GOOGLE MAIL]') |
|
| 3619 | + { |
|
| 3071 | 3620 | $googleMailFolderObject[$k]=$f; |
| 3072 | 3621 | unset($folders[$k]); |
| 3073 | 3622 | $sorted=true; |
| 3074 | - } else { |
|
| 3623 | + } |
|
| 3624 | + else |
|
| 3625 | + { |
|
| 3075 | 3626 | $isAutoFolder=false; |
| 3076 | 3627 | foreach($autoFoldersTmp as $afk=>$aF) |
| 3077 | 3628 | { |
| 3078 | 3629 | //error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]); |
| 3079 | 3630 | if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/ |
| 3080 | 3631 | ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder |
| 3081 | - stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder |
|
| 3632 | + stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) |
|
| 3633 | + { |
|
| 3634 | + // k is parent of an autofolder |
|
| 3082 | 3635 | { |
| 3083 | 3636 | //error_log($k.'->'.$mySpecialUseFolders[$aF]); |
| 3084 | 3637 | $isAutoFolder=true; |
| 3638 | + } |
|
| 3085 | 3639 | $googleAutoFolderObjects[$k]=$f; |
| 3086 | 3640 | break; |
| 3087 | 3641 | } |
| 3088 | 3642 | } |
| 3089 | - if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f; |
|
| 3643 | + if ($isAutoFolder==false) |
|
| 3644 | + { |
|
| 3645 | + $googleSubFolderObjects[$k]=$f; |
|
| 3646 | + } |
|
| 3090 | 3647 | unset($folders[$k]); |
| 3091 | 3648 | $sorted=true; |
| 3092 | 3649 | } |
| 3093 | - } else { |
|
| 3650 | + } |
|
| 3651 | + else |
|
| 3652 | + { |
|
| 3094 | 3653 | $isAutoFolder=false; |
| 3095 | 3654 | foreach($autoFoldersTmp as $afk=>$aF) |
| 3096 | 3655 | { |
| 3097 | 3656 | //error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]); |
| 3098 | 3657 | if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/ |
| 3099 | 3658 | ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder |
| 3100 | - stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder |
|
| 3659 | + stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) |
|
| 3660 | + { |
|
| 3661 | + // k is parent of an autofolder |
|
| 3101 | 3662 | { |
| 3102 | 3663 | //error_log($k.'->'.$mySpecialUseFolders[$aF]); |
| 3103 | 3664 | $isAutoFolder=true; |
| 3665 | + } |
|
| 3104 | 3666 | $autoFolderObjects[$k]=$f; |
| 3105 | 3667 | unset($folders[$k]); |
| 3106 | 3668 | $sorted=true; |
@@ -3116,7 +3678,8 @@ discard block |
||
| 3116 | 3678 | if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix']) |
| 3117 | 3679 | { |
| 3118 | 3680 | if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']|| |
| 3119 | - substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) { |
|
| 3681 | + substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) |
|
| 3682 | + { |
|
| 3120 | 3683 | //error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k); |
| 3121 | 3684 | $typeFolderObject[$type][$k]=$f; |
| 3122 | 3685 | unset($folders[$k]); |
@@ -3143,9 +3706,12 @@ discard block |
||
| 3143 | 3706 | } |
| 3144 | 3707 | } |
| 3145 | 3708 | //error_log(__METHOD__.__LINE__.array2string($autoFolderObjects)); |
| 3146 | - if (!$isGoogleMail) { |
|
| 3709 | + if (!$isGoogleMail) |
|
| 3710 | + { |
|
| 3147 | 3711 | $folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']); |
| 3148 | - } else { |
|
| 3712 | + } |
|
| 3713 | + else |
|
| 3714 | + { |
|
| 3149 | 3715 | // avoid calling sortByAutoFolder as it is not regarding subfolders |
| 3150 | 3716 | $gAutoFolderObjectsTmp = $googleAutoFolderObjects; |
| 3151 | 3717 | unset($googleAutoFolderObjects); |
@@ -3162,7 +3728,10 @@ discard block |
||
| 3162 | 3728 | } |
| 3163 | 3729 | $folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']); |
| 3164 | 3730 | } |
| 3165 | - if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:'); |
|
| 3731 | + if (self::$debugTimes) |
|
| 3732 | + { |
|
| 3733 | + self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:'); |
|
| 3734 | + } |
|
| 3166 | 3735 | //self::$debugTimes=false; |
| 3167 | 3736 | } |
| 3168 | 3737 | // Get counter information and add them to each fetched folders array |
@@ -3212,7 +3781,13 @@ discard block |
||
| 3212 | 3781 | $rv = false; |
| 3213 | 3782 | foreach ($haystack as $k => $v) |
| 3214 | 3783 | { |
| 3215 | - foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;} |
|
| 3784 | + foreach($v as &$sv) |
|
| 3785 | + { |
|
| 3786 | +if (trim($sv)==trim($needle)) |
|
| 3787 | + { |
|
| 3788 | + return $k; |
|
| 3789 | + } |
|
| 3790 | + } |
|
| 3216 | 3791 | } |
| 3217 | 3792 | return $rv; |
| 3218 | 3793 | } |
@@ -3239,7 +3814,10 @@ discard block |
||
| 3239 | 3814 | */ |
| 3240 | 3815 | static function pathToFolderData ($_path, $_hDelimiter) |
| 3241 | 3816 | { |
| 3242 | - if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path; |
|
| 3817 | + if (!strpos($_path, self::DELIMITER)) |
|
| 3818 | + { |
|
| 3819 | + $_path = self::DELIMITER.$_path; |
|
| 3820 | + } |
|
| 3243 | 3821 | list(,$path) = explode(self::DELIMITER, $_path); |
| 3244 | 3822 | $path_chain = $parts = explode($_hDelimiter, $path); |
| 3245 | 3823 | $name = array_pop($parts); |
@@ -3268,7 +3846,10 @@ discard block |
||
| 3268 | 3846 | $b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']); |
| 3269 | 3847 | $pos1 = array_search(trim($a['name']),self::$autoFolders); |
| 3270 | 3848 | $pos2 = array_search(trim($b['name']),self::$autoFolders); |
| 3271 | - if ($pos1 == $pos2) return 0; |
|
| 3849 | + if ($pos1 == $pos2) |
|
| 3850 | + { |
|
| 3851 | + return 0; |
|
| 3852 | + } |
|
| 3272 | 3853 | return ($pos1 < $pos2) ? -1 : 1; |
| 3273 | 3854 | } |
| 3274 | 3855 | |
@@ -3299,7 +3880,10 @@ discard block |
||
| 3299 | 3880 | // 0, 1 und -1 |
| 3300 | 3881 | $pos1 = array_search(trim($a->shortFolderName),self::$autoFolders); |
| 3301 | 3882 | $pos2 = array_search(trim($b->shortFolderName),self::$autoFolders); |
| 3302 | - if ($pos1 == $pos2) return 0; |
|
| 3883 | + if ($pos1 == $pos2) |
|
| 3884 | + { |
|
| 3885 | + return 0; |
|
| 3886 | + } |
|
| 3303 | 3887 | return ($pos1 < $pos2) ? -1 : 1; |
| 3304 | 3888 | } |
| 3305 | 3889 | |
@@ -3320,11 +3904,18 @@ discard block |
||
| 3320 | 3904 | } |
| 3321 | 3905 | catch (\Exception $e) |
| 3322 | 3906 | { |
| 3323 | - if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage()); |
|
| 3907 | + if (self::$debug) |
|
| 3908 | + { |
|
| 3909 | + error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage()); |
|
| 3910 | + } |
|
| 3324 | 3911 | return false; |
| 3325 | 3912 | } |
| 3326 | - if(is_array($folderStatus)) { |
|
| 3327 | - if ($_returnObject===false) return $folderStatus; |
|
| 3913 | + if(is_array($folderStatus)) |
|
| 3914 | + { |
|
| 3915 | + if ($_returnObject===false) |
|
| 3916 | + { |
|
| 3917 | + return $folderStatus; |
|
| 3918 | + } |
|
| 3328 | 3919 | $status = new \stdClass; |
| 3329 | 3920 | $status->messages = $folderStatus['MESSAGES']; |
| 3330 | 3921 | $status->unseen = $folderStatus['UNSEEN']; |
@@ -3351,7 +3942,8 @@ discard block |
||
| 3351 | 3942 | { |
| 3352 | 3943 | #echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>"; |
| 3353 | 3944 | $maxreclevel=25; |
| 3354 | - if ($reclevel > $maxreclevel) { |
|
| 3945 | + if ($reclevel > $maxreclevel) |
|
| 3946 | + { |
|
| 3355 | 3947 | error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter "); |
| 3356 | 3948 | return array(); |
| 3357 | 3949 | } |
@@ -3365,7 +3957,8 @@ discard block |
||
| 3365 | 3957 | //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter)); |
| 3366 | 3958 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx)); |
| 3367 | 3959 | // Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /)) |
| 3368 | - 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"]))) { |
|
| 3960 | + 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"]))) |
|
| 3961 | + { |
|
| 3369 | 3962 | // if there are children fetch them |
| 3370 | 3963 | //echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>"; |
| 3371 | 3964 | |
@@ -3373,7 +3966,8 @@ discard block |
||
| 3373 | 3966 | //$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false); |
| 3374 | 3967 | //_debug_array($buff); |
| 3375 | 3968 | $allMailboxes = array(); |
| 3376 | - foreach ($buff as $mbxname) { |
|
| 3969 | + foreach ($buff as $mbxname) |
|
| 3970 | + { |
|
| 3377 | 3971 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname)); |
| 3378 | 3972 | $mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']); |
| 3379 | 3973 | #echo "About to recur in level $reclevel:".$mbxname."<br>"; |
@@ -3382,9 +3976,14 @@ discard block |
||
| 3382 | 3976 | $allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel)); |
| 3383 | 3977 | } |
| 3384 | 3978 | } |
| 3385 | - 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']; |
|
| 3979 | + if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) |
|
| 3980 | + { |
|
| 3981 | + $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX']; |
|
| 3982 | + } |
|
| 3386 | 3983 | return $allMailboxes; |
| 3387 | - } else { |
|
| 3984 | + } |
|
| 3985 | + else |
|
| 3986 | + { |
|
| 3388 | 3987 | return array($_mailbox); |
| 3389 | 3988 | } |
| 3390 | 3989 | } |
@@ -3408,14 +4007,21 @@ discard block |
||
| 3408 | 4007 | 'Outbox' => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'), |
| 3409 | 4008 | 'Archive' => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'), |
| 3410 | 4009 | ); |
| 3411 | - if ($_type == 'Templates') $_type = 'Template'; // for some reason self::$autofolders uses 'Templates'! |
|
| 4010 | + if ($_type == 'Templates') |
|
| 4011 | + { |
|
| 4012 | + $_type = 'Template'; |
|
| 4013 | + } |
|
| 4014 | + // for some reason self::$autofolders uses 'Templates'! |
|
| 3412 | 4015 | $created = false; |
| 3413 | 4016 | if (!isset($types[$_type])) |
| 3414 | 4017 | { |
| 3415 | 4018 | error_log(__METHOD__.' ('.__LINE__.') '.' '.$_type.' not supported for '.__METHOD__); |
| 3416 | 4019 | return false; |
| 3417 | 4020 | } |
| 3418 | - if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) self::$specialUseFolders = $this->getSpecialUseFolders(); |
|
| 4021 | + if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) |
|
| 4022 | + { |
|
| 4023 | + self::$specialUseFolders = $this->getSpecialUseFolders(); |
|
| 4024 | + } |
|
| 3419 | 4025 | |
| 3420 | 4026 | //highest precedence |
| 3421 | 4027 | try |
@@ -3425,25 +4031,39 @@ discard block |
||
| 3425 | 4031 | catch (\Exception $e) |
| 3426 | 4032 | { |
| 3427 | 4033 | // we know that outbox is not supported, but we use this here, as we autocreate expected SpecialUseFolders in this function |
| 3428 | - if ($_type != 'Outbox') error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage()); |
|
| 4034 | + if ($_type != 'Outbox') |
|
| 4035 | + { |
|
| 4036 | + error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage()); |
|
| 4037 | + } |
|
| 3429 | 4038 | $_folderName = false; |
| 3430 | 4039 | } |
| 3431 | 4040 | // do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist |
| 3432 | - if ($_type == 'Archive') { |
|
| 3433 | - if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) { |
|
| 4041 | + if ($_type == 'Archive') |
|
| 4042 | + { |
|
| 4043 | + if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) |
|
| 4044 | + { |
|
| 3434 | 4045 | return false; |
| 3435 | - } else { |
|
| 4046 | + } |
|
| 4047 | + else |
|
| 4048 | + { |
|
| 3436 | 4049 | return $_folderName; |
| 3437 | 4050 | } |
| 3438 | 4051 | |
| 3439 | 4052 | } |
| 3440 | 4053 | // does the folder exist??? (is configured/preset, but non-existent) |
| 3441 | - if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) { |
|
| 4054 | + if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) |
|
| 4055 | + { |
|
| 3442 | 4056 | try |
| 3443 | 4057 | { |
| 3444 | 4058 | $error = null; |
| 3445 | - if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true; |
|
| 3446 | - if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error); |
|
| 4059 | + if (($_folderName = $this->createFolder('', $_folderName, $error))) |
|
| 4060 | + { |
|
| 4061 | + $created = true; |
|
| 4062 | + } |
|
| 4063 | + if ($error) |
|
| 4064 | + { |
|
| 4065 | + error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error); |
|
| 4066 | + } |
|
| 3447 | 4067 | } |
| 3448 | 4068 | catch(Exception $e) |
| 3449 | 4069 | { |
@@ -3452,9 +4072,16 @@ discard block |
||
| 3452 | 4072 | } |
| 3453 | 4073 | } |
| 3454 | 4074 | // not sure yet if false is the correct behavior on none |
| 3455 | - if ($_folderName =='none') return 'none' ; //false; |
|
| 4075 | + if ($_folderName =='none') |
|
| 4076 | + { |
|
| 4077 | + return 'none' ; |
|
| 4078 | + } |
|
| 4079 | + //false; |
|
| 3456 | 4080 | //no (valid) folder found yet; try specialUseFolders |
| 3457 | - if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f; |
|
| 4081 | + if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) |
|
| 4082 | + { |
|
| 4083 | + $_folderName = $f; |
|
| 4084 | + } |
|
| 3458 | 4085 | //no specialUseFolder; try some Defaults |
| 3459 | 4086 | if (empty($_folderName) && isset($types[$_type])) |
| 3460 | 4087 | { |
@@ -3480,7 +4107,10 @@ discard block |
||
| 3480 | 4107 | $error = null; |
| 3481 | 4108 | $this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error); |
| 3482 | 4109 | $_folderName = $prefix.$types[$_type]['autoFolderName']; |
| 3483 | - if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error); |
|
| 4110 | + if ($error) |
|
| 4111 | + { |
|
| 4112 | + error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error); |
|
| 4113 | + } |
|
| 3484 | 4114 | } |
| 3485 | 4115 | catch(Exception $e) |
| 3486 | 4116 | { |
@@ -3583,25 +4213,35 @@ discard block |
||
| 3583 | 4213 | function isSentFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false) |
| 3584 | 4214 | { |
| 3585 | 4215 | $sentFolder = $this->getSentFolder($_checkexistance); |
| 3586 | - if(empty($sentFolder)) { |
|
| 4216 | + if(empty($sentFolder)) |
|
| 4217 | + { |
|
| 3587 | 4218 | return false; |
| 3588 | 4219 | } |
| 3589 | 4220 | // does the folder exist??? |
| 3590 | - if ($_checkexistance && !$this->folderExists($_folderName)) { |
|
| 4221 | + if ($_checkexistance && !$this->folderExists($_folderName)) |
|
| 4222 | + { |
|
| 3591 | 4223 | return false; |
| 3592 | 4224 | } |
| 3593 | 4225 | |
| 3594 | 4226 | if ($_exactMatch) |
| 3595 | 4227 | { |
| 3596 | - if(false !== stripos($_folderName, $sentFolder)&& strlen($_folderName)==strlen($sentFolder)) { |
|
| 4228 | + if(false !== stripos($_folderName, $sentFolder)&& strlen($_folderName)==strlen($sentFolder)) |
|
| 4229 | + { |
|
| 3597 | 4230 | return true; |
| 3598 | - } else { |
|
| 4231 | + } |
|
| 4232 | + else |
|
| 4233 | + { |
|
| 3599 | 4234 | return false; |
| 3600 | 4235 | } |
| 3601 | - } else { |
|
| 3602 | - if(false !== stripos($_folderName, $sentFolder)) { |
|
| 4236 | + } |
|
| 4237 | + else |
|
| 4238 | + { |
|
| 4239 | + if(false !== stripos($_folderName, $sentFolder)) |
|
| 4240 | + { |
|
| 3603 | 4241 | return true; |
| 3604 | - } else { |
|
| 4242 | + } |
|
| 4243 | + else |
|
| 4244 | + { |
|
| 3605 | 4245 | return false; |
| 3606 | 4246 | } |
| 3607 | 4247 | } |
@@ -3616,23 +4256,33 @@ discard block |
||
| 3616 | 4256 | */ |
| 3617 | 4257 | function isOutbox($_folderName, $_checkexistance=TRUE, $_exactMatch=false) |
| 3618 | 4258 | { |
| 3619 | - if (stripos($_folderName, 'Outbox')===false) { |
|
| 4259 | + if (stripos($_folderName, 'Outbox')===false) |
|
| 4260 | + { |
|
| 3620 | 4261 | return false; |
| 3621 | 4262 | } |
| 3622 | 4263 | // does the folder exist??? |
| 3623 | - if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) { |
|
| 4264 | + if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) |
|
| 4265 | + { |
|
| 3624 | 4266 | $outboxFolder = $this->getOutboxFolder($_checkexistance); |
| 3625 | 4267 | if ($_exactMatch) |
| 3626 | 4268 | { |
| 3627 | - if(false !== stripos($_folderName, $outboxFolder)&& strlen($_folderName)==strlen($outboxFolder)) { |
|
| 4269 | + if(false !== stripos($_folderName, $outboxFolder)&& strlen($_folderName)==strlen($outboxFolder)) |
|
| 4270 | + { |
|
| 3628 | 4271 | return true; |
| 3629 | - } else { |
|
| 4272 | + } |
|
| 4273 | + else |
|
| 4274 | + { |
|
| 3630 | 4275 | return false; |
| 3631 | 4276 | } |
| 3632 | - } else { |
|
| 3633 | - if(false !== stripos($_folderName, $outboxFolder)) { |
|
| 4277 | + } |
|
| 4278 | + else |
|
| 4279 | + { |
|
| 4280 | + if(false !== stripos($_folderName, $outboxFolder)) |
|
| 4281 | + { |
|
| 3634 | 4282 | return true; |
| 3635 | - } else { |
|
| 4283 | + } |
|
| 4284 | + else |
|
| 4285 | + { |
|
| 3636 | 4286 | return false; |
| 3637 | 4287 | } |
| 3638 | 4288 | } |
@@ -3650,25 +4300,38 @@ discard block |
||
| 3650 | 4300 | function isDraftFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false) |
| 3651 | 4301 | { |
| 3652 | 4302 | $draftFolder = $this->getDraftFolder($_checkexistance); |
| 3653 | - if(empty($draftFolder)) { |
|
| 4303 | + if(empty($draftFolder)) |
|
| 4304 | + { |
|
| 3654 | 4305 | return false; |
| 3655 | 4306 | } |
| 3656 | 4307 | // does the folder exist??? |
| 3657 | - if ($_checkexistance && !$this->folderExists($_folderName)) { |
|
| 4308 | + if ($_checkexistance && !$this->folderExists($_folderName)) |
|
| 4309 | + { |
|
| 3658 | 4310 | return false; |
| 3659 | 4311 | } |
| 3660 | - if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8; |
|
| 4312 | + if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) |
|
| 4313 | + { |
|
| 4314 | + $_folderName = $_folderName->utf8; |
|
| 4315 | + } |
|
| 3661 | 4316 | if ($_exactMatch) |
| 3662 | 4317 | { |
| 3663 | - if(false !== stripos($_folderName, $draftFolder)&& strlen($_folderName)==strlen($draftFolder)) { |
|
| 4318 | + if(false !== stripos($_folderName, $draftFolder)&& strlen($_folderName)==strlen($draftFolder)) |
|
| 4319 | + { |
|
| 4320 | + return true; |
|
| 4321 | + } |
|
| 4322 | + else |
|
| 4323 | + { |
|
| 4324 | + return false; |
|
| 4325 | + } |
|
| 4326 | + } |
|
| 4327 | + else |
|
| 4328 | + { |
|
| 4329 | + if(false !== stripos($_folderName, $draftFolder)) |
|
| 4330 | + { |
|
| 3664 | 4331 | return true; |
| 3665 | - } else { |
|
| 3666 | - return false; |
|
| 3667 | 4332 | } |
| 3668 | - } else { |
|
| 3669 | - if(false !== stripos($_folderName, $draftFolder)) { |
|
| 3670 | - return true; |
|
| 3671 | - } else { |
|
| 4333 | + else |
|
| 4334 | + { |
|
| 3672 | 4335 | return false; |
| 3673 | 4336 | } |
| 3674 | 4337 | } |
@@ -3684,25 +4347,35 @@ discard block |
||
| 3684 | 4347 | function isTrashFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false) |
| 3685 | 4348 | { |
| 3686 | 4349 | $trashFolder = $this->getTrashFolder($_checkexistance); |
| 3687 | - if(empty($trashFolder)) { |
|
| 4350 | + if(empty($trashFolder)) |
|
| 4351 | + { |
|
| 3688 | 4352 | return false; |
| 3689 | 4353 | } |
| 3690 | 4354 | // does the folder exist??? |
| 3691 | - if ($_checkexistance && !$this->folderExists($_folderName)) { |
|
| 4355 | + if ($_checkexistance && !$this->folderExists($_folderName)) |
|
| 4356 | + { |
|
| 3692 | 4357 | return false; |
| 3693 | 4358 | } |
| 3694 | 4359 | |
| 3695 | 4360 | if ($_exactMatch) |
| 3696 | 4361 | { |
| 3697 | - if(false !== stripos($_folderName, $trashFolder)&& strlen($_folderName)==strlen($trashFolder)) { |
|
| 4362 | + if(false !== stripos($_folderName, $trashFolder)&& strlen($_folderName)==strlen($trashFolder)) |
|
| 4363 | + { |
|
| 3698 | 4364 | return true; |
| 3699 | - } else { |
|
| 4365 | + } |
|
| 4366 | + else |
|
| 4367 | + { |
|
| 3700 | 4368 | return false; |
| 3701 | 4369 | } |
| 3702 | - } else { |
|
| 3703 | - if(false !== stripos($_folderName, $trashFolder)) { |
|
| 4370 | + } |
|
| 4371 | + else |
|
| 4372 | + { |
|
| 4373 | + if(false !== stripos($_folderName, $trashFolder)) |
|
| 4374 | + { |
|
| 3704 | 4375 | return true; |
| 3705 | - } else { |
|
| 4376 | + } |
|
| 4377 | + else |
|
| 4378 | + { |
|
| 3706 | 4379 | return false; |
| 3707 | 4380 | } |
| 3708 | 4381 | } |
@@ -3718,24 +4391,34 @@ discard block |
||
| 3718 | 4391 | function isTemplateFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false) |
| 3719 | 4392 | { |
| 3720 | 4393 | $templateFolder = $this->getTemplateFolder($_checkexistance); |
| 3721 | - if(empty($templateFolder)) { |
|
| 4394 | + if(empty($templateFolder)) |
|
| 4395 | + { |
|
| 3722 | 4396 | return false; |
| 3723 | 4397 | } |
| 3724 | 4398 | // does the folder exist??? |
| 3725 | - if ($_checkexistance && !$this->folderExists($_folderName)) { |
|
| 4399 | + if ($_checkexistance && !$this->folderExists($_folderName)) |
|
| 4400 | + { |
|
| 3726 | 4401 | return false; |
| 3727 | 4402 | } |
| 3728 | 4403 | if ($_exactMatch) |
| 3729 | 4404 | { |
| 3730 | - if(false !== stripos($_folderName, $templateFolder)&& strlen($_folderName)==strlen($templateFolder)) { |
|
| 4405 | + if(false !== stripos($_folderName, $templateFolder)&& strlen($_folderName)==strlen($templateFolder)) |
|
| 4406 | + { |
|
| 3731 | 4407 | return true; |
| 3732 | - } else { |
|
| 4408 | + } |
|
| 4409 | + else |
|
| 4410 | + { |
|
| 3733 | 4411 | return false; |
| 3734 | 4412 | } |
| 3735 | - } else { |
|
| 3736 | - if(false !== stripos($_folderName, $templateFolder)) { |
|
| 4413 | + } |
|
| 4414 | + else |
|
| 4415 | + { |
|
| 4416 | + if(false !== stripos($_folderName, $templateFolder)) |
|
| 4417 | + { |
|
| 3737 | 4418 | return true; |
| 3738 | - } else { |
|
| 4419 | + } |
|
| 4420 | + else |
|
| 4421 | + { |
|
| 3739 | 4422 | return false; |
| 3740 | 4423 | } |
| 3741 | 4424 | } |
@@ -3754,15 +4437,27 @@ discard block |
||
| 3754 | 4437 | if (empty($_folder)) |
| 3755 | 4438 | { |
| 3756 | 4439 | // this error is more or less without significance, unless we force the check |
| 3757 | - if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace()); |
|
| 4440 | + if ($_forceCheck===true) |
|
| 4441 | + { |
|
| 4442 | + error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace()); |
|
| 4443 | + } |
|
| 3758 | 4444 | return false; |
| 3759 | 4445 | } |
| 3760 | 4446 | // when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder |
| 3761 | - if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true; |
|
| 3762 | - if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder = $_folder->utf8; |
|
| 4447 | + if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) |
|
| 4448 | + { |
|
| 4449 | + return true; |
|
| 4450 | + } |
|
| 4451 | + if (is_a($_folder,"Horde_Imap_Client_Mailbox")) |
|
| 4452 | + { |
|
| 4453 | + $_folder = $_folder->utf8; |
|
| 4454 | + } |
|
| 3763 | 4455 | // reduce traffic within the Instance per User; Expire every 5 hours |
| 3764 | 4456 | //error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace()); |
| 3765 | - if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5); |
|
| 4457 | + if (is_null($folderInfo)) |
|
| 4458 | + { |
|
| 4459 | + $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5); |
|
| 4460 | + } |
|
| 3766 | 4461 | //error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo)); |
| 3767 | 4462 | if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false) |
| 3768 | 4463 | { |
@@ -3780,7 +4475,8 @@ discard block |
||
| 3780 | 4475 | |
| 3781 | 4476 | // does the folder exist??? |
| 3782 | 4477 | //error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server')); |
| 3783 | - if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) { |
|
| 4478 | + if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) |
|
| 4479 | + { |
|
| 3784 | 4480 | //error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID); |
| 3785 | 4481 | //return false; |
| 3786 | 4482 | //try to connect |
@@ -3821,9 +4517,12 @@ discard block |
||
| 3821 | 4517 | |
| 3822 | 4518 | $this->icServer->openMailbox($folderName); |
| 3823 | 4519 | |
| 3824 | - if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") { |
|
| 4520 | + if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") |
|
| 4521 | + { |
|
| 3825 | 4522 | $this->deleteMessages('all',$folderName,'remove_immediately'); |
| 3826 | - } else { |
|
| 4523 | + } |
|
| 4524 | + else |
|
| 4525 | + { |
|
| 3827 | 4526 | $this->icServer->expunge($folderName); |
| 3828 | 4527 | } |
| 3829 | 4528 | } |
@@ -3842,10 +4541,16 @@ discard block |
||
| 3842 | 4541 | { |
| 3843 | 4542 | //error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod); |
| 3844 | 4543 | $oldMailbox = ''; |
| 3845 | - if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox']; |
|
| 4544 | + if (is_null($_folder) || empty($_folder)) |
|
| 4545 | + { |
|
| 4546 | + $_folder = $this->sessionData['mailbox']; |
|
| 4547 | + } |
|
| 3846 | 4548 | if (empty($_messageUID)) |
| 3847 | 4549 | { |
| 3848 | - if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID)); |
|
| 4550 | + if (self::$debug) |
|
| 4551 | + { |
|
| 4552 | + error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID)); |
|
| 4553 | + } |
|
| 3849 | 4554 | return false; |
| 3850 | 4555 | } |
| 3851 | 4556 | elseif ($_messageUID==='all') |
@@ -3855,32 +4560,48 @@ discard block |
||
| 3855 | 4560 | else |
| 3856 | 4561 | { |
| 3857 | 4562 | $uidsToDelete = new Horde_Imap_Client_Ids(); |
| 3858 | - if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID; |
|
| 4563 | + if (!(is_object($_messageUID) || is_array($_messageUID))) |
|
| 4564 | + { |
|
| 4565 | + $_messageUID = (array)$_messageUID; |
|
| 4566 | + } |
|
| 3859 | 4567 | $uidsToDelete->add($_messageUID); |
| 3860 | 4568 | } |
| 3861 | 4569 | $deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method |
| 3862 | - 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"); |
|
| 4570 | + if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately"))) |
|
| 4571 | + { |
|
| 4572 | + $deleteOptions = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted"); |
|
| 4573 | + } |
|
| 3863 | 4574 | //error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions); |
| 3864 | 4575 | $trashFolder = $this->getTrashFolder(); |
| 3865 | 4576 | $draftFolder = $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder']; |
| 3866 | 4577 | $templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder']; |
| 3867 | 4578 | if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") || |
| 3868 | - (strtolower($_folder) == strtolower($draftFolder))) { |
|
| 4579 | + (strtolower($_folder) == strtolower($draftFolder))) |
|
| 4580 | + { |
|
| 3869 | 4581 | $deleteOptions = "remove_immediately"; |
| 3870 | 4582 | } |
| 3871 | - if($this->icServer->getCurrentMailbox() != $_folder) { |
|
| 4583 | + if($this->icServer->getCurrentMailbox() != $_folder) |
|
| 4584 | + { |
|
| 3872 | 4585 | $oldMailbox = $this->icServer->getCurrentMailbox(); |
| 3873 | 4586 | $this->icServer->openMailbox($_folder); |
| 3874 | 4587 | } |
| 3875 | 4588 | //error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions); |
| 3876 | 4589 | $updateCache = false; |
| 3877 | - switch($deleteOptions) { |
|
| 4590 | + switch($deleteOptions) |
|
| 4591 | + { |
|
| 3878 | 4592 | case "move_to_trash": |
| 3879 | 4593 | //error_log(__METHOD__.' ('.__LINE__.') '); |
| 3880 | 4594 | $updateCache = true; |
| 3881 | - if(!empty($trashFolder)) { |
|
| 3882 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID)); |
|
| 3883 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']); |
|
| 4595 | + if(!empty($trashFolder)) |
|
| 4596 | + { |
|
| 4597 | + if (self::$debug) |
|
| 4598 | + { |
|
| 4599 | + error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID)); |
|
| 4600 | + } |
|
| 4601 | + if (self::$debug) |
|
| 4602 | + { |
|
| 4603 | + error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']); |
|
| 4604 | + } |
|
| 3884 | 4605 | // copy messages |
| 3885 | 4606 | try |
| 3886 | 4607 | { |
@@ -3896,7 +4617,10 @@ discard block |
||
| 3896 | 4617 | case "mark_as_deleted": |
| 3897 | 4618 | //error_log(__METHOD__.' ('.__LINE__.') '); |
| 3898 | 4619 | // mark messages as deleted |
| 3899 | - if (is_null($_messageUID)) $_messageUID='all'; |
|
| 4620 | + if (is_null($_messageUID)) |
|
| 4621 | + { |
|
| 4622 | + $_messageUID='all'; |
|
| 4623 | + } |
|
| 3900 | 4624 | foreach((array)$_messageUID as $key =>$uid) |
| 3901 | 4625 | { |
| 3902 | 4626 | //flag messages, that are flagged for deletion as seen too |
@@ -3904,7 +4628,10 @@ discard block |
||
| 3904 | 4628 | $flags = $this->getFlags($uid); |
| 3905 | 4629 | $this->flagMessages('delete', $uid, $_folder); |
| 3906 | 4630 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags)); |
| 3907 | - if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid; |
|
| 4631 | + if (strpos( array2string($flags),'Deleted')!==false) |
|
| 4632 | + { |
|
| 4633 | + $undelete[] = $uid; |
|
| 4634 | + } |
|
| 3908 | 4635 | unset($flags); |
| 3909 | 4636 | } |
| 3910 | 4637 | foreach((array)$undelete as $key =>$uid) |
@@ -3916,7 +4643,10 @@ discard block |
||
| 3916 | 4643 | case "remove_immediately": |
| 3917 | 4644 | //error_log(__METHOD__.' ('.__LINE__.') '); |
| 3918 | 4645 | $updateCache = true; |
| 3919 | - if (is_null($_messageUID)) $_messageUID='all'; |
|
| 4646 | + if (is_null($_messageUID)) |
|
| 4647 | + { |
|
| 4648 | + $_messageUID='all'; |
|
| 4649 | + } |
|
| 3920 | 4650 | if (is_object($_messageUID)) |
| 3921 | 4651 | { |
| 3922 | 4652 | $this->flagMessages('delete', $_messageUID, $_folder); |
@@ -3933,7 +4663,8 @@ discard block |
||
| 3933 | 4663 | $this->icServer->expunge($_folder); |
| 3934 | 4664 | break; |
| 3935 | 4665 | } |
| 3936 | - if($oldMailbox != '') { |
|
| 4666 | + if($oldMailbox != '') |
|
| 4667 | + { |
|
| 3937 | 4668 | $this->icServer->openMailbox($oldMailbox); |
| 3938 | 4669 | } |
| 3939 | 4670 | |
@@ -3947,11 +4678,15 @@ discard block |
||
| 3947 | 4678 | * |
| 3948 | 4679 | * @return null/array flags |
| 3949 | 4680 | */ |
| 3950 | - function getFlags ($_messageUID) { |
|
| 4681 | + function getFlags ($_messageUID) |
|
| 4682 | + { |
|
| 3951 | 4683 | try |
| 3952 | 4684 | { |
| 3953 | 4685 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 3954 | - if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID; |
|
| 4686 | + if (!(is_object($_messageUID) || is_array($_messageUID))) |
|
| 4687 | + { |
|
| 4688 | + $_messageUID = (array)$_messageUID; |
|
| 4689 | + } |
|
| 3955 | 4690 | $uidsToFetch->add($_messageUID); |
| 3956 | 4691 | $_folderName = $this->icServer->getCurrentMailbox(); |
| 3957 | 4692 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -3959,8 +4694,10 @@ discard block |
||
| 3959 | 4694 | $headersNew = $this->icServer->fetch($_folderName, $fquery, array( |
| 3960 | 4695 | 'ids' => $uidsToFetch, |
| 3961 | 4696 | )); |
| 3962 | - if (is_object($headersNew)) { |
|
| 3963 | - foreach($headersNew->ids() as $id) { |
|
| 4697 | + if (is_object($headersNew)) |
|
| 4698 | + { |
|
| 4699 | + foreach($headersNew->ids() as $id) |
|
| 4700 | + { |
|
| 3964 | 4701 | $_headerObject = $headersNew->get($id); |
| 3965 | 4702 | $flags = $_headerObject->getFlags(); |
| 3966 | 4703 | } |
@@ -3985,10 +4722,16 @@ discard block |
||
| 3985 | 4722 | */ |
| 3986 | 4723 | function getNotifyFlags ($_messageUID, $flags=null) |
| 3987 | 4724 | { |
| 3988 | - if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags)); |
|
| 4725 | + if (self::$debug) |
|
| 4726 | + { |
|
| 4727 | + error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags)); |
|
| 4728 | + } |
|
| 3989 | 4729 | try |
| 3990 | 4730 | { |
| 3991 | - if($flags===null) $flags = $this->getFlags($_messageUID); |
|
| 4731 | + if($flags===null) |
|
| 4732 | + { |
|
| 4733 | + $flags = $this->getFlags($_messageUID); |
|
| 4734 | + } |
|
| 3992 | 4735 | } |
| 3993 | 4736 | catch (\Exception $e) |
| 3994 | 4737 | { |
@@ -3996,10 +4739,14 @@ discard block |
||
| 3996 | 4739 | } |
| 3997 | 4740 | |
| 3998 | 4741 | if ( stripos( array2string($flags),'MDNSent')!==false) |
| 3999 | - return true; |
|
| 4742 | + { |
|
| 4743 | + return true; |
|
| 4744 | + } |
|
| 4000 | 4745 | |
| 4001 | 4746 | if ( stripos( array2string($flags),'MDNnotSent')!==false) |
| 4002 | - return false; |
|
| 4747 | + { |
|
| 4748 | + return false; |
|
| 4749 | + } |
|
| 4003 | 4750 | |
| 4004 | 4751 | return null; |
| 4005 | 4752 | } |
@@ -4020,7 +4767,10 @@ discard block |
||
| 4020 | 4767 | //error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']); |
| 4021 | 4768 | if (empty($_messageUID)) |
| 4022 | 4769 | { |
| 4023 | - if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID)); |
|
| 4770 | + if (self::$debug) |
|
| 4771 | + { |
|
| 4772 | + error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID)); |
|
| 4773 | + } |
|
| 4024 | 4774 | return false; |
| 4025 | 4775 | } |
| 4026 | 4776 | $this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox'])); |
@@ -4028,7 +4778,10 @@ discard block |
||
| 4028 | 4778 | if (is_array($_messageUID)&& count($_messageUID)>50) |
| 4029 | 4779 | { |
| 4030 | 4780 | $count = $this->getMailBoxCounters($folder,true); |
| 4031 | - if ($count->messages == count($_messageUID)) $_messageUID='all'; |
|
| 4781 | + if ($count->messages == count($_messageUID)) |
|
| 4782 | + { |
|
| 4783 | + $_messageUID='all'; |
|
| 4784 | + } |
|
| 4032 | 4785 | } |
| 4033 | 4786 | |
| 4034 | 4787 | if ($_messageUID==='all') |
@@ -4037,7 +4790,10 @@ discard block |
||
| 4037 | 4790 | } |
| 4038 | 4791 | else |
| 4039 | 4792 | { |
| 4040 | - if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID; |
|
| 4793 | + if (!(is_object($_messageUID) || is_array($_messageUID))) |
|
| 4794 | + { |
|
| 4795 | + $_messageUID = (array)$_messageUID; |
|
| 4796 | + } |
|
| 4041 | 4797 | $messageUIDs = array_chunk($_messageUID,50,true); |
| 4042 | 4798 | } |
| 4043 | 4799 | try |
@@ -4053,7 +4809,8 @@ discard block |
||
| 4053 | 4809 | $uidsToModify = new Horde_Imap_Client_Ids(); |
| 4054 | 4810 | $uidsToModify->add($uids); |
| 4055 | 4811 | } |
| 4056 | - switch($_flag) { |
|
| 4812 | + switch($_flag) |
|
| 4813 | + { |
|
| 4057 | 4814 | case "delete": |
| 4058 | 4815 | $ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify)); |
| 4059 | 4816 | break; |
@@ -4139,7 +4896,10 @@ discard block |
||
| 4139 | 4896 | { |
| 4140 | 4897 | error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage()); |
| 4141 | 4898 | } |
| 4142 | - if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8; |
|
| 4899 | + if ($folder instanceof Horde_Imap_Client_Mailbox) |
|
| 4900 | + { |
|
| 4901 | + $_folder = $folder->utf8; |
|
| 4902 | + } |
|
| 4143 | 4903 | //error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#'); |
| 4144 | 4904 | self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0; |
| 4145 | 4905 | |
@@ -4168,7 +4928,10 @@ discard block |
||
| 4168 | 4928 | //$deleteOptions = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"]; |
| 4169 | 4929 | if (empty($_messageUID)) |
| 4170 | 4930 | { |
| 4171 | - if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID)); |
|
| 4931 | + if (self::$debug) |
|
| 4932 | + { |
|
| 4933 | + error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID)); |
|
| 4934 | + } |
|
| 4172 | 4935 | return false; |
| 4173 | 4936 | } |
| 4174 | 4937 | elseif ($_messageUID==='all') |
@@ -4180,7 +4943,10 @@ discard block |
||
| 4180 | 4943 | { |
| 4181 | 4944 | //error_log(__METHOD__." Message(s): ".implode(',',$_messageUID)); |
| 4182 | 4945 | $uidsToMove = new Horde_Imap_Client_Ids(); |
| 4183 | - if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID; |
|
| 4946 | + if (!(is_object($_messageUID) || is_array($_messageUID))) |
|
| 4947 | + { |
|
| 4948 | + $_messageUID = (array)$_messageUID; |
|
| 4949 | + } |
|
| 4184 | 4950 | $uidsToMove->add($_messageUID); |
| 4185 | 4951 | } |
| 4186 | 4952 | $sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']); |
@@ -4202,12 +4968,14 @@ discard block |
||
| 4202 | 4968 | |
| 4203 | 4969 | //error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew)); |
| 4204 | 4970 | |
| 4205 | - if (is_object($headersNew)) { |
|
| 4971 | + if (is_object($headersNew)) |
|
| 4972 | + { |
|
| 4206 | 4973 | $c=0; |
| 4207 | 4974 | $retUid = new Horde_Imap_Client_Ids(); |
| 4208 | 4975 | // we copy chunks of 5 to avoid too much memory and/or server stress |
| 4209 | 4976 | // some servers seem not to allow/support the appendig of multiple messages. so we are down to one |
| 4210 | - foreach($headersNew as &$_headerObject) { |
|
| 4977 | + foreach($headersNew as &$_headerObject) |
|
| 4978 | + { |
|
| 4211 | 4979 | $c++; |
| 4212 | 4980 | $flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message |
| 4213 | 4981 | $date = $_headerObject->getImapDate(); |
@@ -4291,7 +5059,11 @@ discard block |
||
| 4291 | 5059 | { |
| 4292 | 5060 | try { |
| 4293 | 5061 | $date = new DateTime($_date); // parse date & time including timezone (throws exception, if not parsable) |
| 4294 | - if ($convert2usertime) $date->setUser(); // convert to user-time |
|
| 5062 | + if ($convert2usertime) |
|
| 5063 | + { |
|
| 5064 | + $date->setUser(); |
|
| 5065 | + } |
|
| 5066 | + // convert to user-time |
|
| 4295 | 5067 | $date2return = $date->format($format); |
| 4296 | 5068 | } |
| 4297 | 5069 | catch(\Exception $e) |
@@ -4325,9 +5097,15 @@ discard block |
||
| 4325 | 5097 | static function htmlentities($_string, $_charset=false) |
| 4326 | 5098 | { |
| 4327 | 5099 | //setting the charset (if not given) |
| 4328 | - if ($_charset===false) $_charset = self::$displayCharset; |
|
| 5100 | + if ($_charset===false) |
|
| 5101 | + { |
|
| 5102 | + $_charset = self::$displayCharset; |
|
| 5103 | + } |
|
| 4329 | 5104 | $string = @htmlentities($_string, ENT_QUOTES, $_charset, false); |
| 4330 | - if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false); |
|
| 5105 | + if (empty($string) && !empty($_string)) |
|
| 5106 | + { |
|
| 5107 | + $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false); |
|
| 5108 | + } |
|
| 4331 | 5109 | return $string; |
| 4332 | 5110 | } |
| 4333 | 5111 | |
@@ -4347,18 +5125,41 @@ discard block |
||
| 4347 | 5125 | $_html = str_replace(array('&amp;','<DIV><BR></DIV>',"<DIV> </DIV>",'<div> </div>','</td></font>','<br><td>','<tr></tr>','<o:p></o:p>','<o:p>','</o:p>'), |
| 4348 | 5126 | array('&', '<BR>', '<BR>', '<BR>', '</font></td>','<td>', '', '', '', ''),$_html); |
| 4349 | 5127 | //$_html = str_replace(array('&amp;'),array('&'),$_html); |
| 4350 | - if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags |
|
| 4351 | - if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head |
|
| 5128 | + if (stripos($_html,'style')!==false) |
|
| 5129 | + { |
|
| 5130 | + Mail\Html::replaceTagsCompletley($_html,'style'); |
|
| 5131 | + } |
|
| 5132 | + // clean out empty or pagewide style definitions / left over tags |
|
| 5133 | + if (stripos($_html,'head')!==false) |
|
| 5134 | + { |
|
| 5135 | + Mail\Html::replaceTagsCompletley($_html,'head'); |
|
| 5136 | + } |
|
| 5137 | + // Strip out stuff in head |
|
| 4352 | 5138 | //if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs |
| 4353 | 5139 | //if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs |
| 4354 | 5140 | //error_log(__METHOD__.' ('.__LINE__.') '.$_html); |
| 4355 | 5141 | |
| 4356 | - if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html); |
|
| 5142 | + if (get_magic_quotes_gpc() === 1) |
|
| 5143 | + { |
|
| 5144 | + $_html = stripslashes($_html); |
|
| 5145 | + } |
|
| 4357 | 5146 | // Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards |
| 4358 | - if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype'); |
|
| 4359 | - if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false); |
|
| 4360 | - if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false); |
|
| 4361 | - if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR'); |
|
| 5147 | + if (stripos($_html,'!doctype')!==false) |
|
| 5148 | + { |
|
| 5149 | + Mail\Html::replaceTagsCompletley($_html,'!doctype'); |
|
| 5150 | + } |
|
| 5151 | + if (stripos($_html,'?xml:namespace')!==false) |
|
| 5152 | + { |
|
| 5153 | + Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false); |
|
| 5154 | + } |
|
| 5155 | + if (stripos($_html,'?xml version')!==false) |
|
| 5156 | + { |
|
| 5157 | + Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false); |
|
| 5158 | + } |
|
| 5159 | + if (strpos($_html,'!CURSOR')!==false) |
|
| 5160 | + { |
|
| 5161 | + Mail\Html::replaceTagsCompletley($_html,'!CURSOR'); |
|
| 5162 | + } |
|
| 4362 | 5163 | // htmLawed filter only the 'body' |
| 4363 | 5164 | //preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches); |
| 4364 | 5165 | //if ($matches[2]) |
@@ -4397,8 +5198,10 @@ discard block |
||
| 4397 | 5198 | //$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1 |
| 4398 | 5199 | $CharsetFound=false; |
| 4399 | 5200 | //echo "#".$_mimePartObject->encoding.'#<br>'; |
| 4400 | - if(is_array($_mimePartObject->parameters)) { |
|
| 4401 | - if(isset($_mimePartObject->parameters['CHARSET'])) { |
|
| 5201 | + if(is_array($_mimePartObject->parameters)) |
|
| 5202 | + { |
|
| 5203 | + if(isset($_mimePartObject->parameters['CHARSET'])) |
|
| 5204 | + { |
|
| 4402 | 5205 | $charSet = $_mimePartObject->parameters['CHARSET']; |
| 4403 | 5206 | $CharsetFound=true; |
| 4404 | 5207 | } |
@@ -4419,7 +5222,10 @@ discard block |
||
| 4419 | 5222 | function decodeMimePart($_mimeMessage, $_encoding, $_charset = '') |
| 4420 | 5223 | { |
| 4421 | 5224 | // decode the part |
| 4422 | - if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true)); |
|
| 5225 | + if (self::$debug) |
|
| 5226 | + { |
|
| 5227 | + error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true)); |
|
| 5228 | + } |
|
| 4423 | 5229 | switch (strtoupper($_encoding)) |
| 4424 | 5230 | { |
| 4425 | 5231 | case 'BASE64': |
@@ -4460,13 +5266,19 @@ discard block |
||
| 4460 | 5266 | // sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that |
| 4461 | 5267 | // as attachment AND as abstracted ical information (we use our notification style here). |
| 4462 | 5268 | $partText = $partCalendar = $partHTML = null; |
| 4463 | - if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure)); |
|
| 5269 | + if (self::$debug) |
|
| 5270 | + { |
|
| 5271 | + _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure)); |
|
| 5272 | + } |
|
| 4464 | 5273 | //error_log(__METHOD__.' ('.__LINE__.') '); |
| 4465 | 5274 | $ignore_first_part = true; |
| 4466 | 5275 | foreach($_structure->contentTypeMap() as $mime_id => $mime_type) |
| 4467 | 5276 | { |
| 4468 | 5277 | //error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part); |
| 4469 | - if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>"; |
|
| 5278 | + if (self::$debug) |
|
| 5279 | + { |
|
| 5280 | + echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>"; |
|
| 5281 | + } |
|
| 4470 | 5282 | |
| 4471 | 5283 | if ($ignore_first_part) |
| 4472 | 5284 | { |
@@ -4482,15 +5294,24 @@ discard block |
||
| 4482 | 5294 | switch($mimePart->getSubType()) |
| 4483 | 5295 | { |
| 4484 | 5296 | case 'plain': |
| 4485 | - if ($mimePart->getBytes() > 0) $partText = $mimePart; |
|
| 5297 | + if ($mimePart->getBytes() > 0) |
|
| 5298 | + { |
|
| 5299 | + $partText = $mimePart; |
|
| 5300 | + } |
|
| 4486 | 5301 | break; |
| 4487 | 5302 | |
| 4488 | 5303 | case 'html': |
| 4489 | - if ($mimePart->getBytes() > 0) $partHTML = $mimePart; |
|
| 5304 | + if ($mimePart->getBytes() > 0) |
|
| 5305 | + { |
|
| 5306 | + $partHTML = $mimePart; |
|
| 5307 | + } |
|
| 4490 | 5308 | break; |
| 4491 | 5309 | |
| 4492 | 5310 | case 'calendar': |
| 4493 | - if ($mimePart->getBytes() > 0) $partCalendar = $mimePart; |
|
| 5311 | + if ($mimePart->getBytes() > 0) |
|
| 5312 | + { |
|
| 5313 | + $partCalendar = $mimePart; |
|
| 5314 | + } |
|
| 4494 | 5315 | break; |
| 4495 | 5316 | } |
| 4496 | 5317 | break; |
@@ -4503,7 +5324,10 @@ discard block |
||
| 4503 | 5324 | if (count($mimePart->getParts()) > 1) |
| 4504 | 5325 | { |
| 4505 | 5326 | // in a multipart alternative we treat the multipart/related as html part |
| 4506 | - if (self::$debug) error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts"); |
|
| 5327 | + if (self::$debug) |
|
| 5328 | + { |
|
| 5329 | + error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts"); |
|
| 5330 | + } |
|
| 4507 | 5331 | $partHTML = $mimePart; |
| 4508 | 5332 | break 3; // GET OUT OF LOOP, will be processed according to type |
| 4509 | 5333 | } |
@@ -4585,9 +5409,15 @@ discard block |
||
| 4585 | 5409 | */ |
| 4586 | 5410 | function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array(), &$partCalendar=null) |
| 4587 | 5411 | { |
| 4588 | - if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>"; |
|
| 5412 | + if (self::$debug) |
|
| 5413 | + { |
|
| 5414 | + echo __METHOD__."$_uid, $_htmlMode<br>"; |
|
| 5415 | + } |
|
| 4589 | 5416 | $bodyPart = array(); |
| 4590 | - if (self::$debug) _debug_array($_structure); |
|
| 5417 | + if (self::$debug) |
|
| 5418 | + { |
|
| 5419 | + _debug_array($_structure); |
|
| 5420 | + } |
|
| 4591 | 5421 | |
| 4592 | 5422 | $ignore_first_part = true; |
| 4593 | 5423 | //$skipParts = array(); |
@@ -4595,7 +5425,10 @@ discard block |
||
| 4595 | 5425 | foreach($_structure->contentTypeMap() as $mime_id => $mime_type) |
| 4596 | 5426 | { |
| 4597 | 5427 | //error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"); |
| 4598 | - if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>"; |
|
| 5428 | + if (self::$debug) |
|
| 5429 | + { |
|
| 5430 | + echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>"; |
|
| 5431 | + } |
|
| 4599 | 5432 | if ($ignore_first_part) |
| 4600 | 5433 | { |
| 4601 | 5434 | $ignore_first_part = false; |
@@ -4613,7 +5446,10 @@ discard block |
||
| 4613 | 5446 | switch($part->getPrimaryType()) |
| 4614 | 5447 | { |
| 4615 | 5448 | case 'multipart': |
| 4616 | - if ($part->getDisposition() == 'attachment') continue; |
|
| 5449 | + if ($part->getDisposition() == 'attachment') |
|
| 5450 | + { |
|
| 5451 | + continue; |
|
| 5452 | + } |
|
| 4617 | 5453 | switch($part->getSubType()) |
| 4618 | 5454 | { |
| 4619 | 5455 | case 'alternative': |
@@ -4678,7 +5514,9 @@ discard block |
||
| 4678 | 5514 | if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment') |
| 4679 | 5515 | { |
| 4680 | 5516 | $skipParts[$mime_id.'.0'] = $mime_type; |
| 4681 | - foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;} |
|
| 5517 | + foreach($part->contentTypeMap() as $sub_id => $sub_type) |
|
| 5518 | + { |
|
| 5519 | +$skipParts[$sub_id] = $sub_type;} |
|
| 4682 | 5520 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts)); |
| 4683 | 5521 | //break 2; |
| 4684 | 5522 | } |
@@ -4721,7 +5559,10 @@ discard block |
||
| 4721 | 5559 | */ |
| 4722 | 5560 | function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true) |
| 4723 | 5561 | { |
| 4724 | - if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)"); |
|
| 5562 | + if (self::$debug) |
|
| 5563 | + { |
|
| 5564 | + error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)"); |
|
| 5565 | + } |
|
| 4725 | 5566 | |
| 4726 | 5567 | if (empty($_folder)) |
| 4727 | 5568 | { |
@@ -4730,7 +5571,10 @@ discard block |
||
| 4730 | 5571 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']); |
| 4731 | 5572 | // querying contents of body part |
| 4732 | 5573 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 4733 | - if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid; |
|
| 5574 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 5575 | + { |
|
| 5576 | + $_uid = (array)$_uid; |
|
| 5577 | + } |
|
| 4734 | 5578 | $uidsToFetch->add($_uid); |
| 4735 | 5579 | |
| 4736 | 5580 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -4738,9 +5582,12 @@ discard block |
||
| 4738 | 5582 | 'peek' => $_preserveSeen, |
| 4739 | 5583 | 'decode' => true, // try decode on server, does NOT neccessary work |
| 4740 | 5584 | ); |
| 4741 | - if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder))) |
|
| 5585 | + if ($_tryDecodingServerside===false) |
|
| 5586 | + { |
|
| 5587 | + // || ($_tryDecodingServerside&&$this->isDraftFolder($_folder))) |
|
| 4742 | 5588 | { |
| 4743 | 5589 | $_tryDecodingServerside=false; |
| 5590 | + } |
|
| 4744 | 5591 | $fetchParams = array( |
| 4745 | 5592 | 'peek' => $_preserveSeen, |
| 4746 | 5593 | ); |
@@ -4782,7 +5629,10 @@ discard block |
||
| 4782 | 5629 | { |
| 4783 | 5630 | //error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace()); |
| 4784 | 5631 | $bodyPart = array(); |
| 4785 | - if (self::$debug) _debug_array(array($_structure,function_backtrace())); |
|
| 5632 | + if (self::$debug) |
|
| 5633 | + { |
|
| 5634 | + _debug_array(array($_structure,function_backtrace())); |
|
| 5635 | + } |
|
| 4786 | 5636 | |
| 4787 | 5637 | if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text'))) |
| 4788 | 5638 | { |
@@ -4833,8 +5683,12 @@ discard block |
||
| 4833 | 5683 | */ |
| 4834 | 5684 | function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '', &$calendar_part=null) |
| 4835 | 5685 | { |
| 4836 | - if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>"; |
|
| 4837 | - if($_htmlOptions != '') { |
|
| 5686 | + if (self::$debug) |
|
| 5687 | + { |
|
| 5688 | + echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>"; |
|
| 5689 | + } |
|
| 5690 | + if($_htmlOptions != '') |
|
| 5691 | + { |
|
| 4838 | 5692 | $this->htmlOptions = $_htmlOptions; |
| 4839 | 5693 | } |
| 4840 | 5694 | if (empty($_folder)) |
@@ -4924,7 +5778,9 @@ discard block |
||
| 4924 | 5778 | default: |
| 4925 | 5779 | $bodyPart = array($this->getTextPart($_uid, $_structure, $this->htmlOptions, $_preserveSeen)); |
| 4926 | 5780 | } |
| 4927 | - } else { |
|
| 5781 | + } |
|
| 5782 | + else |
|
| 5783 | + { |
|
| 4928 | 5784 | // what if the structure->disposition is attachment ,... |
| 4929 | 5785 | } |
| 4930 | 5786 | return self::normalizeBodyParts($bodyPart); |
@@ -4935,13 +5791,18 @@ discard block |
||
| 4935 | 5791 | { |
| 4936 | 5792 | case 'rfc822': |
| 4937 | 5793 | $newStructure = $_structure->getParts(); |
| 4938 | - if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);} |
|
| 5794 | + if (self::$debug) |
|
| 5795 | + { |
|
| 5796 | +echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);} |
|
| 4939 | 5797 | return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder)); |
| 4940 | 5798 | } |
| 4941 | 5799 | break; |
| 4942 | 5800 | |
| 4943 | 5801 | default: |
| 4944 | - if (self::$debug) _debug_array($_structure); |
|
| 5802 | + if (self::$debug) |
|
| 5803 | + { |
|
| 5804 | + _debug_array($_structure); |
|
| 5805 | + } |
|
| 4945 | 5806 | return array( |
| 4946 | 5807 | array( |
| 4947 | 5808 | 'body' => lang('The mimeparser can not parse this message.').$_structure->getType(), |
@@ -4965,9 +5826,12 @@ discard block |
||
| 4965 | 5826 | { |
| 4966 | 5827 | foreach($_bodyParts as $singleBodyPart) |
| 4967 | 5828 | { |
| 4968 | - if (!isset($singleBodyPart['body'])) { |
|
| 5829 | + if (!isset($singleBodyPart['body'])) |
|
| 5830 | + { |
|
| 4969 | 5831 | $buff = self::normalizeBodyParts($singleBodyPart); |
| 4970 | - foreach ((array)$buff as $val) { $body2return[] = $val;} |
|
| 5832 | + foreach ((array)$buff as $val) |
|
| 5833 | + { |
|
| 5834 | +$body2return[] = $val;} |
|
| 4971 | 5835 | continue; |
| 4972 | 5836 | } |
| 4973 | 5837 | $body2return[] = $singleBodyPart; |
@@ -4993,13 +5857,20 @@ discard block |
||
| 4993 | 5857 | $message=''; |
| 4994 | 5858 | for($i=0; $i<count($bodyParts); $i++) |
| 4995 | 5859 | { |
| 4996 | - if (!isset($bodyParts[$i]['body'])) { |
|
| 5860 | + if (!isset($bodyParts[$i]['body'])) |
|
| 5861 | + { |
|
| 4997 | 5862 | $bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy); |
| 4998 | 5863 | $message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body']; |
| 4999 | 5864 | continue; |
| 5000 | 5865 | } |
| 5001 | - if (isset($bodyParts[$i]['error'])) continue; |
|
| 5002 | - if (empty($bodyParts[$i]['body'])) continue; |
|
| 5866 | + if (isset($bodyParts[$i]['error'])) |
|
| 5867 | + { |
|
| 5868 | + continue; |
|
| 5869 | + } |
|
| 5870 | + if (empty($bodyParts[$i]['body'])) |
|
| 5871 | + { |
|
| 5872 | + continue; |
|
| 5873 | + } |
|
| 5003 | 5874 | // some characterreplacements, as they fail to translate |
| 5004 | 5875 | $sar = array( |
| 5005 | 5876 | '@(\x84|\x93|\x94)@', |
@@ -5026,13 +5897,17 @@ discard block |
||
| 5026 | 5897 | $bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']); |
| 5027 | 5898 | } |
| 5028 | 5899 | |
| 5029 | - if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']); |
|
| 5900 | + if ($bodyParts[$i]['charSet']===false) |
|
| 5901 | + { |
|
| 5902 | + $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']); |
|
| 5903 | + } |
|
| 5030 | 5904 | // add line breaks to $bodyParts |
| 5031 | 5905 | //error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']); |
| 5032 | 5906 | $newBody = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']); |
| 5033 | 5907 | //error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody); |
| 5034 | 5908 | $mailClass->activeMimeType = 'text/plain'; |
| 5035 | - if ($bodyParts[$i]['mimeType'] == 'text/html') { |
|
| 5909 | + if ($bodyParts[$i]['mimeType'] == 'text/html') |
|
| 5910 | + { |
|
| 5036 | 5911 | $mailClass->activeMimeType = $bodyParts[$i]['mimeType']; |
| 5037 | 5912 | if (!$preserveHTML) |
| 5038 | 5913 | { |
@@ -5078,15 +5953,28 @@ discard block |
||
| 5078 | 5953 | // as we switched off HTMLaweds tidy functionality |
| 5079 | 5954 | $newBody = str_replace(array('&amp;','<DIV><BR></DIV>',"<DIV> </DIV>",'<div> </div>'),array('&','<BR>','<BR>','<BR>'),$newBody); |
| 5080 | 5955 | $newBody = $htmLawed->run($newBody,self::$htmLawed_config); |
| 5081 | - if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3]; |
|
| 5956 | + if ($hasOther && $preserveHTML) |
|
| 5957 | + { |
|
| 5958 | + $newBody = $matches[1]. $newBody. $matches[3]; |
|
| 5959 | + } |
|
| 5082 | 5960 | $alreadyHtmlLawed=true; |
| 5083 | 5961 | } |
| 5084 | 5962 | //error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody); |
| 5085 | - if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true); |
|
| 5963 | + if ($preserveHTML==false) |
|
| 5964 | + { |
|
| 5965 | + $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true); |
|
| 5966 | + } |
|
| 5086 | 5967 | //error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody); |
| 5087 | - if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n |
|
| 5968 | + if ($preserveHTML==false) |
|
| 5969 | + { |
|
| 5970 | + $newBody = nl2br($newBody); |
|
| 5971 | + } |
|
| 5972 | + // we need this, as htmLawed removes \r\n |
|
| 5088 | 5973 | /*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted |
| 5089 | - if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody); |
|
| 5974 | + if ($preserveHTML==false) |
|
| 5975 | + { |
|
| 5976 | + $newBody = str_replace("<br />","\r\n",$newBody); |
|
| 5977 | + } |
|
| 5090 | 5978 | //error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody); |
| 5091 | 5979 | } |
| 5092 | 5980 | $message .= $newBody; |
@@ -5123,12 +6011,12 @@ discard block |
||
| 5123 | 6011 | substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith |
| 5124 | 6012 | ) |
| 5125 | 6013 | ) |
| 5126 | - ) |
|
| 5127 | - { |
|
| 6014 | + ) { |
|
| 5128 | 6015 | $s=explode(" ", $line); |
| 5129 | 6016 | $line = ""; |
| 5130 | 6017 | $linecnt = 0; |
| 5131 | - foreach ($s as &$v) { |
|
| 6018 | + foreach ($s as &$v) |
|
| 6019 | + { |
|
| 5132 | 6020 | $cnt = strlen($v); |
| 5133 | 6021 | // only break long words within the wordboundaries, |
| 5134 | 6022 | // but it may destroy links, so we check for href and dont do it if we find one |
@@ -5138,14 +6026,20 @@ discard block |
||
| 5138 | 6026 | $v=wordwrap($v, $allowedLength, $cut, true); |
| 5139 | 6027 | } |
| 5140 | 6028 | // the rest should be broken at the start of the new word that exceeds the limit |
| 5141 | - if ($linecnt+$cnt > $allowedLength) { |
|
| 6029 | + if ($linecnt+$cnt > $allowedLength) |
|
| 6030 | + { |
|
| 5142 | 6031 | $v=$cut.$v; |
| 5143 | 6032 | #$linecnt = 0; |
| 5144 | 6033 | $linecnt =strlen($v)-strlen($cut); |
| 5145 | - } else { |
|
| 6034 | + } |
|
| 6035 | + else |
|
| 6036 | + { |
|
| 5146 | 6037 | $linecnt += $cnt; |
| 5147 | 6038 | } |
| 5148 | - if (strlen($v)) $line .= (strlen($line) ? " " : "").$v; |
|
| 6039 | + if (strlen($v)) |
|
| 6040 | + { |
|
| 6041 | + $line .= (strlen($line) ? " " : "").$v; |
|
| 6042 | + } |
|
| 5149 | 6043 | } |
| 5150 | 6044 | } |
| 5151 | 6045 | $newStr .= $line . "\n"; |
@@ -5166,11 +6060,18 @@ discard block |
||
| 5166 | 6060 | function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false) |
| 5167 | 6061 | { |
| 5168 | 6062 | //error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace()); |
| 5169 | - if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6063 | + if (empty($_folder)) |
|
| 6064 | + { |
|
| 6065 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6066 | + } |
|
| 5170 | 6067 | //error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder"); |
| 5171 | - if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) { |
|
| 6068 | + if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) |
|
| 6069 | + { |
|
| 5172 | 6070 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5173 | - if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid; |
|
| 6071 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6072 | + { |
|
| 6073 | + $_uid = (array)$_uid; |
|
| 6074 | + } |
|
| 5174 | 6075 | $uidsToFetch->add($_uid); |
| 5175 | 6076 | |
| 5176 | 6077 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -5180,8 +6081,10 @@ discard block |
||
| 5180 | 6081 | $headersNew = $this->icServer->fetch($_folder, $fquery, array( |
| 5181 | 6082 | 'ids' => $uidsToFetch, |
| 5182 | 6083 | )); |
| 5183 | - if (is_object($headersNew)) { |
|
| 5184 | - foreach($headersNew as &$_headerObject) { |
|
| 6084 | + if (is_object($headersNew)) |
|
| 6085 | + { |
|
| 6086 | + foreach($headersNew as &$_headerObject) |
|
| 6087 | + { |
|
| 5185 | 6088 | $env = $_headerObject->getEnvelope(); |
| 5186 | 6089 | //_debug_array($envFields->singleFields()); |
| 5187 | 6090 | $singleFields = $envFields->singleFields(); |
@@ -5198,7 +6101,10 @@ discard block |
||
| 5198 | 6101 | //error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses)); |
| 5199 | 6102 | $envelope[$v]=$env->$v->addresses; |
| 5200 | 6103 | $address = array(); |
| 5201 | - if (!is_array($envelope[$v])) break; |
|
| 6104 | + if (!is_array($envelope[$v])) |
|
| 6105 | + { |
|
| 6106 | + break; |
|
| 6107 | + } |
|
| 5202 | 6108 | foreach ($envelope[$v] as $k => $ad) |
| 5203 | 6109 | { |
| 5204 | 6110 | if (stripos($ad,'@')===false) |
@@ -5235,7 +6141,9 @@ discard block |
||
| 5235 | 6141 | } |
| 5236 | 6142 | } |
| 5237 | 6143 | return $envelope; |
| 5238 | - } else { |
|
| 6144 | + } |
|
| 6145 | + else |
|
| 6146 | + { |
|
| 5239 | 6147 | |
| 5240 | 6148 | $headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder); |
| 5241 | 6149 | |
@@ -5246,19 +6154,43 @@ discard block |
||
| 5246 | 6154 | 'SUBJECT' => ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']), |
| 5247 | 6155 | 'MESSAGE_ID' => $headers['MESSAGE-ID'] |
| 5248 | 6156 | ); |
| 5249 | - if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO']; |
|
| 5250 | - if (isset($headers['REFERENCES'])) $newData['REFERENCES'] = $headers['REFERENCES']; |
|
| 5251 | - if (isset($headers['THREAD-TOPIC'])) $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC']; |
|
| 5252 | - if (isset($headers['THREAD-INDEX'])) $newData['THREAD-INDEX'] = $headers['THREAD-INDEX']; |
|
| 5253 | - if (isset($headers['LIST-ID'])) $newData['LIST-ID'] = $headers['LIST-ID']; |
|
| 5254 | - if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE']; |
|
| 6157 | + if (isset($headers['IN-REPLY-TO'])) |
|
| 6158 | + { |
|
| 6159 | + $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO']; |
|
| 6160 | + } |
|
| 6161 | + if (isset($headers['REFERENCES'])) |
|
| 6162 | + { |
|
| 6163 | + $newData['REFERENCES'] = $headers['REFERENCES']; |
|
| 6164 | + } |
|
| 6165 | + if (isset($headers['THREAD-TOPIC'])) |
|
| 6166 | + { |
|
| 6167 | + $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC']; |
|
| 6168 | + } |
|
| 6169 | + if (isset($headers['THREAD-INDEX'])) |
|
| 6170 | + { |
|
| 6171 | + $newData['THREAD-INDEX'] = $headers['THREAD-INDEX']; |
|
| 6172 | + } |
|
| 6173 | + if (isset($headers['LIST-ID'])) |
|
| 6174 | + { |
|
| 6175 | + $newData['LIST-ID'] = $headers['LIST-ID']; |
|
| 6176 | + } |
|
| 6177 | + if (isset($headers['SIZE'])) |
|
| 6178 | + { |
|
| 6179 | + $newData['SIZE'] = $headers['SIZE']; |
|
| 6180 | + } |
|
| 5255 | 6181 | //_debug_array($newData); |
| 5256 | 6182 | $recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'); |
| 5257 | - foreach($recepientList as $recepientType) { |
|
| 5258 | - if(isset($headers[$recepientType])) { |
|
| 5259 | - if ($decode) $headers[$recepientType] = self::decode_header($headers[$recepientType],true); |
|
| 6183 | + foreach($recepientList as $recepientType) |
|
| 6184 | + { |
|
| 6185 | + if(isset($headers[$recepientType])) |
|
| 6186 | + { |
|
| 6187 | + if ($decode) |
|
| 6188 | + { |
|
| 6189 | + $headers[$recepientType] = self::decode_header($headers[$recepientType],true); |
|
| 6190 | + } |
|
| 5260 | 6191 | //error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType])); |
| 5261 | - foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) { |
|
| 6192 | + foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) |
|
| 6193 | + { |
|
| 5262 | 6194 | $addressData = array( |
| 5263 | 6195 | 'PERSONAL_NAME' => $singleAddress->personal ? $singleAddress->personal : 'NIL', |
| 5264 | 6196 | 'AT_DOMAIN_LIST' => $singleAddress->adl ? $singleAddress->adl : 'NIL', |
@@ -5266,17 +6198,25 @@ discard block |
||
| 5266 | 6198 | 'HOST_NAME' => $singleAddress->host ? $singleAddress->host : 'NIL', |
| 5267 | 6199 | 'EMAIL' => $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox, |
| 5268 | 6200 | ); |
| 5269 | - if($addressData['PERSONAL_NAME'] != 'NIL') { |
|
| 6201 | + if($addressData['PERSONAL_NAME'] != 'NIL') |
|
| 6202 | + { |
|
| 5270 | 6203 | $addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal); |
| 5271 | - } else { |
|
| 6204 | + } |
|
| 6205 | + else |
|
| 6206 | + { |
|
| 5272 | 6207 | $addressData['RFC822_EMAIL'] = 'NIL'; |
| 5273 | 6208 | } |
| 5274 | 6209 | $newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData; |
| 5275 | 6210 | } |
| 5276 | - } else { |
|
| 5277 | - if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') { |
|
| 6211 | + } |
|
| 6212 | + else |
|
| 6213 | + { |
|
| 6214 | + if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') |
|
| 6215 | + { |
|
| 5278 | 6216 | $newData[$recepientType] = $newData['FROM']; |
| 5279 | - } else { |
|
| 6217 | + } |
|
| 6218 | + else |
|
| 6219 | + { |
|
| 5280 | 6220 | $newData[$recepientType] = array(); |
| 5281 | 6221 | } |
| 5282 | 6222 | } |
@@ -5299,9 +6239,15 @@ discard block |
||
| 5299 | 6239 | function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='') |
| 5300 | 6240 | { |
| 5301 | 6241 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder); |
| 5302 | - if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6242 | + if (empty($_folder)) |
|
| 6243 | + { |
|
| 6244 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6245 | + } |
|
| 5303 | 6246 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5304 | - if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid; |
|
| 6247 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6248 | + { |
|
| 6249 | + $_uid = (array)$_uid; |
|
| 6250 | + } |
|
| 5305 | 6251 | $uidsToFetch->add($_uid); |
| 5306 | 6252 | |
| 5307 | 6253 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -5319,7 +6265,8 @@ discard block |
||
| 5319 | 6265 | $headersNew = $this->icServer->fetch($_folder, $fquery, array( |
| 5320 | 6266 | 'ids' => $uidsToFetch, |
| 5321 | 6267 | )); |
| 5322 | - if (is_object($headersNew)) { |
|
| 6268 | + if (is_object($headersNew)) |
|
| 6269 | + { |
|
| 5323 | 6270 | foreach($headersNew as $_fetchObject) |
| 5324 | 6271 | { |
| 5325 | 6272 | $headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE); |
@@ -5341,11 +6288,17 @@ discard block |
||
| 5341 | 6288 | } |
| 5342 | 6289 | if ($decode === 'object') |
| 5343 | 6290 | { |
| 5344 | - if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']); |
|
| 6291 | + if (is_object($headers)) |
|
| 6292 | + { |
|
| 6293 | + $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']); |
|
| 6294 | + } |
|
| 5345 | 6295 | return $headers; |
| 5346 | 6296 | } |
| 5347 | 6297 | $retValue = is_object($headers) ? $headers->toArray():array(); |
| 5348 | - if ($size) $retValue['size'] = $size; |
|
| 6298 | + if ($size) |
|
| 6299 | + { |
|
| 6300 | + $retValue['size'] = $size; |
|
| 6301 | + } |
|
| 5349 | 6302 | } |
| 5350 | 6303 | $retValue = array_change_key_case($retValue,CASE_UPPER); |
| 5351 | 6304 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue)); |
@@ -5377,10 +6330,16 @@ discard block |
||
| 5377 | 6330 | function getMessageRawHeader($_uid, $_partID = '', $_folder = '') |
| 5378 | 6331 | { |
| 5379 | 6332 | static $rawHeaders; |
| 5380 | - if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6333 | + if (empty($_folder)) |
|
| 6334 | + { |
|
| 6335 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6336 | + } |
|
| 5381 | 6337 | //error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder"); |
| 5382 | 6338 | |
| 5383 | - 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); |
|
| 6339 | + if (is_null($rawHeaders)||!is_array($rawHeaders)) |
|
| 6340 | + { |
|
| 6341 | + $rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 6342 | + } |
|
| 5384 | 6343 | if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)])) |
| 5385 | 6344 | { |
| 5386 | 6345 | //error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder"); |
@@ -5388,7 +6347,10 @@ discard block |
||
| 5388 | 6347 | } |
| 5389 | 6348 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5390 | 6349 | $uid = $_uid; |
| 5391 | - if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid; |
|
| 6350 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6351 | + { |
|
| 6352 | + $uid = (array)$_uid; |
|
| 6353 | + } |
|
| 5392 | 6354 | $uidsToFetch->add($uid); |
| 5393 | 6355 | |
| 5394 | 6356 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -5404,8 +6366,10 @@ discard block |
||
| 5404 | 6366 | $headersNew = $this->icServer->fetch($_folder, $fquery, array( |
| 5405 | 6367 | 'ids' => $uidsToFetch, |
| 5406 | 6368 | )); |
| 5407 | - if (is_object($headersNew)) { |
|
| 5408 | - foreach($headersNew as &$_headerObject) { |
|
| 6369 | + if (is_object($headersNew)) |
|
| 6370 | + { |
|
| 6371 | + foreach($headersNew as &$_headerObject) |
|
| 6372 | + { |
|
| 5409 | 6373 | $retValue = $_headerObject->getHeaderText(); |
| 5410 | 6374 | if ($_partID != '') |
| 5411 | 6375 | { |
@@ -5433,22 +6397,33 @@ discard block |
||
| 5433 | 6397 | static function &getStyles($_bodyParts) |
| 5434 | 6398 | { |
| 5435 | 6399 | $style = ''; |
| 5436 | - if (empty($_bodyParts)) return ""; |
|
| 5437 | - foreach((array)$_bodyParts as $singleBodyPart) { |
|
| 5438 | - if (!isset($singleBodyPart['body'])) { |
|
| 6400 | + if (empty($_bodyParts)) |
|
| 6401 | + { |
|
| 6402 | + return ""; |
|
| 6403 | + } |
|
| 6404 | + foreach((array)$_bodyParts as $singleBodyPart) |
|
| 6405 | + { |
|
| 6406 | + if (!isset($singleBodyPart['body'])) |
|
| 6407 | + { |
|
| 5439 | 6408 | $singleBodyPart['body'] = self::getStyles($singleBodyPart); |
| 5440 | 6409 | $style .= $singleBodyPart['body']; |
| 5441 | 6410 | continue; |
| 5442 | 6411 | } |
| 5443 | 6412 | |
| 5444 | - if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']); |
|
| 6413 | + if ($singleBodyPart['charSet']===false) |
|
| 6414 | + { |
|
| 6415 | + $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']); |
|
| 6416 | + } |
|
| 5445 | 6417 | $singleBodyPart['body'] = Translation::convert( |
| 5446 | 6418 | $singleBodyPart['body'], |
| 5447 | 6419 | strtolower($singleBodyPart['charSet']) |
| 5448 | 6420 | ); |
| 5449 | 6421 | $ct = 0; |
| 5450 | 6422 | $newStyle=array(); |
| 5451 | - if (stripos($singleBodyPart['body'],'<style')!==false) $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle); |
|
| 6423 | + if (stripos($singleBodyPart['body'],'<style')!==false) |
|
| 6424 | + { |
|
| 6425 | + $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle); |
|
| 6426 | + } |
|
| 5452 | 6427 | if ($ct>0) |
| 5453 | 6428 | { |
| 5454 | 6429 | //error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle)); |
@@ -5480,7 +6455,11 @@ discard block |
||
| 5480 | 6455 | // CSS Security |
| 5481 | 6456 | // http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets |
| 5482 | 6457 | $css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style); |
| 5483 | - if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included |
|
| 6458 | + if (stripos($css,'script')!==false) |
|
| 6459 | + { |
|
| 6460 | + Mail\Html::replaceTagsCompletley($css,'script'); |
|
| 6461 | + } |
|
| 6462 | + // Strip out script that may be included |
|
| 5484 | 6463 | // 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 |
| 5485 | 6464 | // as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it |
| 5486 | 6465 | $css = str_replace(array(':','<!--','-->'),array(': ','',''),$css); |
@@ -5502,8 +6481,14 @@ discard block |
||
| 5502 | 6481 | { |
| 5503 | 6482 | //TODO: caching einbauen static! |
| 5504 | 6483 | static $rawBody; |
| 5505 | - if (is_null($rawBody)) $rawBody = array(); |
|
| 5506 | - if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6484 | + if (is_null($rawBody)) |
|
| 6485 | + { |
|
| 6486 | + $rawBody = array(); |
|
| 6487 | + } |
|
| 6488 | + if (empty($_folder)) |
|
| 6489 | + { |
|
| 6490 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6491 | + } |
|
| 5507 | 6492 | if (!$_stream && isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)])) |
| 5508 | 6493 | { |
| 5509 | 6494 | //error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder"); |
@@ -5512,7 +6497,10 @@ discard block |
||
| 5512 | 6497 | |
| 5513 | 6498 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5514 | 6499 | $uid = $_uid; |
| 5515 | - if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid; |
|
| 6500 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6501 | + { |
|
| 6502 | + $uid = (array)$_uid; |
|
| 6503 | + } |
|
| 5516 | 6504 | $uidsToFetch->add($uid); |
| 5517 | 6505 | |
| 5518 | 6506 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -5525,8 +6513,10 @@ discard block |
||
| 5525 | 6513 | $headersNew = $this->icServer->fetch($_folder, $fquery, array( |
| 5526 | 6514 | 'ids' => $uidsToFetch, |
| 5527 | 6515 | )); |
| 5528 | - if (is_object($headersNew)) { |
|
| 5529 | - foreach($headersNew as &$_headerObject) { |
|
| 6516 | + if (is_object($headersNew)) |
|
| 6517 | + { |
|
| 6518 | + foreach($headersNew as &$_headerObject) |
|
| 6519 | + { |
|
| 5530 | 6520 | $body = $_headerObject->getFullMsg($_stream); |
| 5531 | 6521 | if ($_partID != '') |
| 5532 | 6522 | { |
@@ -5562,14 +6552,20 @@ discard block |
||
| 5562 | 6552 | */ |
| 5563 | 6553 | function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false) |
| 5564 | 6554 | { |
| 5565 | - if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID"); |
|
| 6555 | + if (self::$debug) |
|
| 6556 | + { |
|
| 6557 | + error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID"); |
|
| 6558 | + } |
|
| 5566 | 6559 | |
| 5567 | 6560 | if (empty($_folder)) |
| 5568 | 6561 | { |
| 5569 | 6562 | $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
| 5570 | 6563 | } |
| 5571 | 6564 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5572 | - if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid; |
|
| 6565 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6566 | + { |
|
| 6567 | + $_uid = (array)$_uid; |
|
| 6568 | + } |
|
| 5573 | 6569 | $uidsToFetch->add($_uid); |
| 5574 | 6570 | try |
| 5575 | 6571 | { |
@@ -5578,7 +6574,10 @@ discard block |
||
| 5578 | 6574 | // $fquery->envelope(); |
| 5579 | 6575 | // $fquery->size(); |
| 5580 | 6576 | $_fquery->structure(); |
| 5581 | - if ($_partID) $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen)); |
|
| 6577 | + if ($_partID) |
|
| 6578 | + { |
|
| 6579 | + $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen)); |
|
| 6580 | + } |
|
| 5582 | 6581 | |
| 5583 | 6582 | $mail = $this->icServer->fetch($_folder, $_fquery, array( |
| 5584 | 6583 | 'ids' => $uidsToFetch, |
@@ -5609,16 +6608,28 @@ discard block |
||
| 5609 | 6608 | */ |
| 5610 | 6609 | function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='') |
| 5611 | 6610 | { |
| 5612 | - if (self::$debug) error_log( __METHOD__.":$_uid, $_partID"); |
|
| 5613 | - if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6611 | + if (self::$debug) |
|
| 6612 | + { |
|
| 6613 | + error_log( __METHOD__.":$_uid, $_partID"); |
|
| 6614 | + } |
|
| 6615 | + if (empty($_folder)) |
|
| 6616 | + { |
|
| 6617 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6618 | + } |
|
| 5614 | 6619 | $attachments = array(); |
| 5615 | 6620 | if (!isset($_structure)) |
| 5616 | 6621 | { |
| 5617 | 6622 | $_structure = $this->getStructure($_uid, $_partID,$_folder,true); |
| 5618 | 6623 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true)); |
| 5619 | 6624 | } |
| 5620 | - if (!$_structure || !$_structure->contentTypeMap()) return array(); |
|
| 5621 | - if (!empty($_partID)) $_structure = $_structure->getPart($_partID); |
|
| 6625 | + if (!$_structure || !$_structure->contentTypeMap()) |
|
| 6626 | + { |
|
| 6627 | + return array(); |
|
| 6628 | + } |
|
| 6629 | + if (!empty($_partID)) |
|
| 6630 | + { |
|
| 6631 | + $_structure = $_structure->getPart($_partID); |
|
| 6632 | + } |
|
| 5622 | 6633 | $skipParts = array(); |
| 5623 | 6634 | $tnefParts = array(); |
| 5624 | 6635 | $skip = 0; |
@@ -5647,7 +6658,13 @@ discard block |
||
| 5647 | 6658 | if ($mime_type=='message/rfc822' && $_partID!=$mime_id) |
| 5648 | 6659 | { |
| 5649 | 6660 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap())); |
| 5650 | - foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;} |
|
| 6661 | + foreach($part->contentTypeMap() as $sub_id => $sub_type) |
|
| 6662 | + { |
|
| 6663 | +if ($sub_id != $mime_id) |
|
| 6664 | + { |
|
| 6665 | + $skipParts[$sub_id] = $sub_type; |
|
| 6666 | + } |
|
| 6667 | + } |
|
| 5651 | 6668 | } |
| 5652 | 6669 | if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text') |
| 5653 | 6670 | { |
@@ -5658,7 +6675,10 @@ discard block |
||
| 5658 | 6675 | $partDisposition='attachment'; |
| 5659 | 6676 | } |
| 5660 | 6677 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts)); |
| 5661 | - if (array_key_exists($mime_id,$skipParts)) continue; |
|
| 6678 | + if (array_key_exists($mime_id,$skipParts)) |
|
| 6679 | + { |
|
| 6680 | + continue; |
|
| 6681 | + } |
|
| 5662 | 6682 | |
| 5663 | 6683 | if ($partDisposition == 'attachment' || |
| 5664 | 6684 | (($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') || |
@@ -5669,23 +6689,41 @@ discard block |
||
| 5669 | 6689 | { |
| 5670 | 6690 | // if type is message/rfc822 and _partID is given, and MimeID equals partID |
| 5671 | 6691 | // we attempt to fetch "ourselves" |
| 5672 | - if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue; |
|
| 6692 | + if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') |
|
| 6693 | + { |
|
| 6694 | + continue; |
|
| 6695 | + } |
|
| 5673 | 6696 | $attachment = $part->getAllDispositionParameters(); |
| 5674 | 6697 | $attachment['disposition'] = $part->getDisposition(); |
| 5675 | 6698 | $attachment['mimeType'] = $mime_type; |
| 5676 | 6699 | $attachment['uid'] = $_uid; |
| 5677 | 6700 | $attachment['partID'] = $mime_id; |
| 5678 | - if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName(); |
|
| 6701 | + if (!isset($attachment['name'])||empty($attachment['name'])) |
|
| 6702 | + { |
|
| 6703 | + $attachment['name'] = $part->getName(); |
|
| 6704 | + } |
|
| 5679 | 6705 | if ($fetchTextCalendar) |
| 5680 | 6706 | { |
| 5681 | 6707 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters())); |
| 5682 | 6708 | $method = $part->getContentTypeParameter('method'); |
| 5683 | - if ($method) $attachment['method'] = $method; |
|
| 5684 | - if (!isset($attachment['name'])) $attachment['name'] = 'event.ics'; |
|
| 6709 | + if ($method) |
|
| 6710 | + { |
|
| 6711 | + $attachment['method'] = $method; |
|
| 6712 | + } |
|
| 6713 | + if (!isset($attachment['name'])) |
|
| 6714 | + { |
|
| 6715 | + $attachment['name'] = 'event.ics'; |
|
| 6716 | + } |
|
| 5685 | 6717 | } |
| 5686 | 6718 | $attachment['size'] = $part->getBytes(); |
| 5687 | - if (($cid = $part->getContentId())) $attachment['cid'] = $cid; |
|
| 5688 | - 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); |
|
| 6719 | + if (($cid = $part->getContentId())) |
|
| 6720 | + { |
|
| 6721 | + $attachment['cid'] = $cid; |
|
| 6722 | + } |
|
| 6723 | + if (empty($attachment['name'])) |
|
| 6724 | + { |
|
| 6725 | + $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type); |
|
| 6726 | + } |
|
| 5689 | 6727 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment)); |
| 5690 | 6728 | //typical winmail.dat attachment is |
| 5691 | 6729 | //Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat) |
@@ -5721,14 +6759,26 @@ discard block |
||
| 5721 | 6759 | $attachment['uid'] = $tnp['uid']; |
| 5722 | 6760 | $attachment['partID'] = $tnp['partID']; |
| 5723 | 6761 | $attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id; |
| 5724 | - if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName(); |
|
| 6762 | + if (!isset($attachment['name'])||empty($attachment['name'])) |
|
| 6763 | + { |
|
| 6764 | + $attachment['name'] = $part->getName(); |
|
| 6765 | + } |
|
| 5725 | 6766 | $attachment['size'] = $part->getBytes(); |
| 5726 | - if (($cid = $part->getContentId())) $attachment['cid'] = $cid; |
|
| 5727 | - 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']); |
|
| 6767 | + if (($cid = $part->getContentId())) |
|
| 6768 | + { |
|
| 6769 | + $attachment['cid'] = $cid; |
|
| 6770 | + } |
|
| 6771 | + if (empty($attachment['name'])) |
|
| 6772 | + { |
|
| 6773 | + $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']); |
|
| 6774 | + } |
|
| 5728 | 6775 | $attachments[] = $attachment; |
| 5729 | 6776 | } |
| 5730 | 6777 | } |
| 5731 | - if ($tnefResolved===false) $attachments[]=$tnp; |
|
| 6778 | + if ($tnefResolved===false) |
|
| 6779 | + { |
|
| 6780 | + $attachments[]=$tnp; |
|
| 6781 | + } |
|
| 5732 | 6782 | } |
| 5733 | 6783 | } |
| 5734 | 6784 | //error_log(__METHOD__.__LINE__.array2string($attachments)); |
@@ -5832,8 +6882,14 @@ discard block |
||
| 5832 | 6882 | |
| 5833 | 6883 | $attachment = $part->getAllDispositionParameters(); |
| 5834 | 6884 | $attachment['mimeType'] = $part->getType(); |
| 5835 | - if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName(); |
|
| 5836 | - if (($cid = $part->getContentId())) $attachment['cid'] = $cid; |
|
| 6885 | + if (!isset($attachment['filename'])||empty($attachment['filename'])) |
|
| 6886 | + { |
|
| 6887 | + $attachment['filename'] = $part->getName(); |
|
| 6888 | + } |
|
| 6889 | + if (($cid = $part->getContentId())) |
|
| 6890 | + { |
|
| 6891 | + $attachment['cid'] = $cid; |
|
| 6892 | + } |
|
| 5837 | 6893 | if (empty($attachment['filename'])) |
| 5838 | 6894 | { |
| 5839 | 6895 | $attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])? |
@@ -5845,7 +6901,10 @@ discard block |
||
| 5845 | 6901 | $attachments[$_uid.'@'.$_partID.'@'.$mime_id] = $attachment; |
| 5846 | 6902 | } |
| 5847 | 6903 | } |
| 5848 | - if (!is_array($attachments)) return false; |
|
| 6904 | + if (!is_array($attachments)) |
|
| 6905 | + { |
|
| 6906 | + return false; |
|
| 6907 | + } |
|
| 5849 | 6908 | return $attachments; |
| 5850 | 6909 | } |
| 5851 | 6910 | |
@@ -5864,10 +6923,16 @@ discard block |
||
| 5864 | 6923 | function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null) |
| 5865 | 6924 | { |
| 5866 | 6925 | //error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace()); |
| 5867 | - if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6926 | + if (!isset($_folder)) |
|
| 6927 | + { |
|
| 6928 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6929 | + } |
|
| 5868 | 6930 | |
| 5869 | 6931 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5870 | - if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid; |
|
| 6932 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6933 | + { |
|
| 6934 | + $_uid = (array)$_uid; |
|
| 6935 | + } |
|
| 5871 | 6936 | $uidsToFetch->add($_uid); |
| 5872 | 6937 | |
| 5873 | 6938 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -5876,8 +6941,10 @@ discard block |
||
| 5876 | 6941 | $headersNew = $this->icServer->fetch($_folder, $fquery, array( |
| 5877 | 6942 | 'ids' => $uidsToFetch, |
| 5878 | 6943 | )); |
| 5879 | - if (is_object($headersNew)) { |
|
| 5880 | - foreach($headersNew as $id=>$_headerObject) { |
|
| 6944 | + if (is_object($headersNew)) |
|
| 6945 | + { |
|
| 6946 | + foreach($headersNew as $id=>$_headerObject) |
|
| 6947 | + { |
|
| 5881 | 6948 | $body = $_headerObject->getFullMsg(); |
| 5882 | 6949 | if ($_partID != '') |
| 5883 | 6950 | { |
@@ -5891,7 +6958,10 @@ discard block |
||
| 5891 | 6958 | } |
| 5892 | 6959 | // if $partDisposition is empty, we assume attachment, and hope that the function |
| 5893 | 6960 | // itself is only triggered to fetch attachments |
| 5894 | - if (empty($partDisposition)) $partDisposition='attachment'; |
|
| 6961 | + if (empty($partDisposition)) |
|
| 6962 | + { |
|
| 6963 | + $partDisposition='attachment'; |
|
| 6964 | + } |
|
| 5895 | 6965 | if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar'))) |
| 5896 | 6966 | { |
| 5897 | 6967 | //$headerObject=$part->getAllDispositionParameters();//not used anywhere around here |
@@ -5900,13 +6970,19 @@ discard block |
||
| 5900 | 6970 | $charset = $part->getContentTypeParameter('charset'); |
| 5901 | 6971 | //$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" ); |
| 5902 | 6972 | $this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime); |
| 5903 | - if ($_returnPart) return $part; |
|
| 6973 | + if ($_returnPart) |
|
| 6974 | + { |
|
| 6975 | + return $part; |
|
| 6976 | + } |
|
| 5904 | 6977 | } |
| 5905 | 6978 | } |
| 5906 | 6979 | } |
| 5907 | 6980 | } |
| 5908 | 6981 | $ext = MimeMagic::mime2ext($structure_mime); |
| 5909 | - if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext; |
|
| 6982 | + if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) |
|
| 6983 | + { |
|
| 6984 | + $filename = trim($filename).'.'.$ext; |
|
| 6985 | + } |
|
| 5910 | 6986 | if (!$part) |
| 5911 | 6987 | { |
| 5912 | 6988 | throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder"); |
@@ -5922,7 +6998,10 @@ discard block |
||
| 5922 | 6998 | ); |
| 5923 | 6999 | |
| 5924 | 7000 | // try guessing the mimetype, if we get the application/octet-stream |
| 5925 | - if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']); |
|
| 7001 | + if (strtolower($attachmentData['type']) == 'application/octet-stream') |
|
| 7002 | + { |
|
| 7003 | + $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']); |
|
| 7004 | + } |
|
| 5926 | 7005 | # if the attachment holds a winmail number and is a winmail.dat then we have to handle that. |
| 5927 | 7006 | if ( $filename == 'winmail.dat' && $_winmail_nr) |
| 5928 | 7007 | { |
@@ -5945,9 +7024,18 @@ discard block |
||
| 5945 | 7024 | if ($_winmail_nr == $wantedPart.'@'.$mime_id) |
| 5946 | 7025 | { |
| 5947 | 7026 | //error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment)); |
| 5948 | - if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName(); |
|
| 5949 | - if (($cid = $part->getContentId())) $attachment['cid'] = $cid; |
|
| 5950 | - 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']); |
|
| 7027 | + if (!isset($attachment['filename'])||empty($attachment['filename'])) |
|
| 7028 | + { |
|
| 7029 | + $attachment['filename'] = $part->getName(); |
|
| 7030 | + } |
|
| 7031 | + if (($cid = $part->getContentId())) |
|
| 7032 | + { |
|
| 7033 | + $attachment['cid'] = $cid; |
|
| 7034 | + } |
|
| 7035 | + if (empty($attachment['filename'])) |
|
| 7036 | + { |
|
| 7037 | + $attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']); |
|
| 7038 | + } |
|
| 5951 | 7039 | $wmattach = $attachment; |
| 5952 | 7040 | $wmattach['attachment'] = $part->getContents(array('stream'=>$_stream)); |
| 5953 | 7041 | |
@@ -5957,7 +7045,10 @@ discard block |
||
| 5957 | 7045 | if ($tnefResolved) |
| 5958 | 7046 | { |
| 5959 | 7047 | $ext = MimeMagic::mime2ext($wmattach['mimeType']); |
| 5960 | - if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext; |
|
| 7048 | + if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) |
|
| 7049 | + { |
|
| 7050 | + $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext; |
|
| 7051 | + } |
|
| 5961 | 7052 | $attachmentData = array( |
| 5962 | 7053 | 'type' => $wmattach['mimeType'], |
| 5963 | 7054 | 'filename' => $wmattach['filename'], |
@@ -5987,7 +7078,10 @@ discard block |
||
| 5987 | 7078 | static $uid=null, $part=null, $structure=null; |
| 5988 | 7079 | //error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part"); |
| 5989 | 7080 | |
| 5990 | - if(empty($_cid)) return false; |
|
| 7081 | + if(empty($_cid)) |
|
| 7082 | + { |
|
| 7083 | + return false; |
|
| 7084 | + } |
|
| 5991 | 7085 | |
| 5992 | 7086 | if ($_uid != $uid || $_part != $part) |
| 5993 | 7087 | { |
@@ -6012,13 +7106,19 @@ discard block |
||
| 6012 | 7106 | $attachment = $part; |
| 6013 | 7107 | } |
| 6014 | 7108 | // everything else we only consider after we checked all |
| 6015 | - if (!isset($attachment)) $attachment = $part; |
|
| 7109 | + if (!isset($attachment)) |
|
| 7110 | + { |
|
| 7111 | + $attachment = $part; |
|
| 7112 | + } |
|
| 6016 | 7113 | // do we want content fetched, can be done later, if not needed |
| 6017 | 7114 | if (isset($_stream)) |
| 6018 | 7115 | { |
| 6019 | 7116 | $this->fetchPartContents($_uid, $attachment, $_stream); |
| 6020 | 7117 | } |
| 6021 | - if (isset($attachment)) break; |
|
| 7118 | + if (isset($attachment)) |
|
| 7119 | + { |
|
| 7120 | + break; |
|
| 7121 | + } |
|
| 6022 | 7122 | } |
| 6023 | 7123 | } |
| 6024 | 7124 | // set name as filename, if not set |
@@ -6049,10 +7149,17 @@ discard block |
||
| 6049 | 7149 | */ |
| 6050 | 7150 | public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null) |
| 6051 | 7151 | { |
| 6052 | - if (is_null($part)) return null;//new Horde_Mime_Part; |
|
| 7152 | + if (is_null($part)) |
|
| 7153 | + { |
|
| 7154 | + return null; |
|
| 7155 | + } |
|
| 7156 | + //new Horde_Mime_Part; |
|
| 6053 | 7157 | $encoding = null; |
| 6054 | 7158 | $fetchAsBinary = true; |
| 6055 | - if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false; |
|
| 7159 | + if ($_mimetype && strtolower($_mimetype)=='message/rfc822') |
|
| 7160 | + { |
|
| 7161 | + $fetchAsBinary = false; |
|
| 7162 | + } |
|
| 6056 | 7163 | // we need to set content on structure to decode transfer encoding |
| 6057 | 7164 | $part->setContents( |
| 6058 | 7165 | $this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary), |
@@ -6089,7 +7196,10 @@ discard block |
||
| 6089 | 7196 | // the recent flag is the default enforced here ; as we assume the _flags is always set, |
| 6090 | 7197 | // we default it to hordes default (Recent) (, other wise we should not pass the parameter |
| 6091 | 7198 | // for flags at all) |
| 6092 | - if (empty($_flags)) $_flags = '\\Recent'; |
|
| 7199 | + if (empty($_flags)) |
|
| 7200 | + { |
|
| 7201 | + $_flags = '\\Recent'; |
|
| 7202 | + } |
|
| 6093 | 7203 | //if (!is_array($_flags) && stripos($_flags,',')!==false) $_flags=explode(',',$_flags); |
| 6094 | 7204 | //if (!is_array($_flags)) $_flags = (array) $_flags; |
| 6095 | 7205 | try |
@@ -6106,18 +7216,27 @@ discard block |
||
| 6106 | 7216 | } |
| 6107 | 7217 | catch (\Exception $e) |
| 6108 | 7218 | { |
| 6109 | - if (self::$debug) error_log("Could not append Message: ".$e->getMessage()); |
|
| 7219 | + if (self::$debug) |
|
| 7220 | + { |
|
| 7221 | + error_log("Could not append Message: ".$e->getMessage()); |
|
| 7222 | + } |
|
| 6110 | 7223 | throw new Exception\WrongUserinput(lang("Could not append Message:").' '.$e->getMessage().': '.$e->details); |
| 6111 | 7224 | //return false; |
| 6112 | 7225 | } |
| 6113 | 7226 | //error_log(__METHOD__.' ('.__LINE__.') '.' appended UID:'.$messageid); |
| 6114 | 7227 | //$messageid = true; // for debug reasons only |
| 6115 | - if ($messageid === true || empty($messageid)) // try to figure out the message uid |
|
| 7228 | + if ($messageid === true || empty($messageid)) |
|
| 7229 | + { |
|
| 7230 | + // try to figure out the message uid |
|
| 6116 | 7231 | { |
| 6117 | 7232 | $list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false); |
| 7233 | + } |
|
| 6118 | 7234 | if ($list) |
| 6119 | 7235 | { |
| 6120 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list)); |
|
| 7236 | + if (self::$debug) |
|
| 7237 | + { |
|
| 7238 | + error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list)); |
|
| 7239 | + } |
|
| 6121 | 7240 | $messageid = $list['header'][0]['uid']; |
| 6122 | 7241 | } |
| 6123 | 7242 | } |
@@ -6158,7 +7277,10 @@ discard block |
||
| 6158 | 7277 | { |
| 6159 | 7278 | //echo __METHOD__." called for $uid,$partid <br>"; |
| 6160 | 7279 | $headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox); |
| 6161 | - if (empty($headers)) return false; |
|
| 7280 | + if (empty($headers)) |
|
| 7281 | + { |
|
| 7282 | + return false; |
|
| 7283 | + } |
|
| 6162 | 7284 | // dont force retrieval of the textpart, let mailClass preferences decide |
| 6163 | 7285 | $bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox); |
| 6164 | 7286 | // if we do not want HTML but there is no TextRepresentation with the message itself, try converting |
@@ -6176,15 +7298,30 @@ discard block |
||
| 6176 | 7298 | //error_log(array2string($bodyParts)); |
| 6177 | 7299 | $attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array(); |
| 6178 | 7300 | |
| 6179 | - if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO']; |
|
| 6180 | - elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM']; |
|
| 6181 | - elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER']; |
|
| 6182 | - if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC']; |
|
| 7301 | + if ($mailClass->isSentFolder($mailbox)) |
|
| 7302 | + { |
|
| 7303 | + $mailaddress = $headers['TO']; |
|
| 7304 | + } |
|
| 7305 | + elseif (isset($headers['FROM'])) |
|
| 7306 | + { |
|
| 7307 | + $mailaddress = $headers['FROM']; |
|
| 7308 | + } |
|
| 7309 | + elseif (isset($headers['SENDER'])) |
|
| 7310 | + { |
|
| 7311 | + $mailaddress = $headers['SENDER']; |
|
| 7312 | + } |
|
| 7313 | + if (isset($headers['CC'])) |
|
| 7314 | + { |
|
| 7315 | + $mailaddress .= ','.$headers['CC']; |
|
| 7316 | + } |
|
| 6183 | 7317 | //_debug_array(array($headers,$mailaddress)); |
| 6184 | 7318 | $subject = $headers['SUBJECT']; |
| 6185 | 7319 | |
| 6186 | 7320 | $message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML); |
| 6187 | - if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>'; |
|
| 7321 | + if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') |
|
| 7322 | + { |
|
| 7323 | + $message = '<pre>'.$message.'</pre>'; |
|
| 7324 | + } |
|
| 6188 | 7325 | $headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : ''); |
| 6189 | 7326 | $message = $headdata.$message; |
| 6190 | 7327 | //echo __METHOD__.'<br>'; |
@@ -6235,7 +7372,8 @@ discard block |
||
| 6235 | 7372 | $attachments[$num]['attachment'] = $c->getContents(); |
| 6236 | 7373 | } |
| 6237 | 7374 | // no attempt to convert, if we dont know about the charset |
| 6238 | - if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) { |
|
| 7375 | + if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) |
|
| 7376 | + { |
|
| 6239 | 7377 | // we do not try guessing the charset, if it is not set |
| 6240 | 7378 | //if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']); |
| 6241 | 7379 | Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']); |
@@ -6256,7 +7394,10 @@ discard block |
||
| 6256 | 7394 | unset($attachments[$num]['attachment']); |
| 6257 | 7395 | } |
| 6258 | 7396 | } |
| 6259 | - if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages); |
|
| 7397 | + if (is_array($attachedMessages)) |
|
| 7398 | + { |
|
| 7399 | + $attachments = array_merge($attachments,$attachedMessages); |
|
| 7400 | + } |
|
| 6260 | 7401 | } |
| 6261 | 7402 | return array( |
| 6262 | 7403 | 'mailaddress'=>$mailaddress, |
@@ -6278,10 +7419,17 @@ discard block |
||
| 6278 | 7419 | { |
| 6279 | 7420 | $c = 0; |
| 6280 | 7421 | // use the standardIdentity |
| 6281 | - foreach($_identities as $key => $acc) { |
|
| 6282 | - if ($c==0) $identity = $acc; |
|
| 7422 | + foreach($_identities as $key => $acc) |
|
| 7423 | + { |
|
| 7424 | + if ($c==0) |
|
| 7425 | + { |
|
| 7426 | + $identity = $acc; |
|
| 7427 | + } |
|
| 6283 | 7428 | //error_log(__METHOD__.__LINE__." $key == $_profile_id "); |
| 6284 | - if ($key==$_profile_id) $identity = $acc; |
|
| 7429 | + if ($key==$_profile_id) |
|
| 7430 | + { |
|
| 7431 | + $identity = $acc; |
|
| 7432 | + } |
|
| 6285 | 7433 | $c++; |
| 6286 | 7434 | } |
| 6287 | 7435 | return $identity; |
@@ -6297,20 +7445,53 @@ discard block |
||
| 6297 | 7445 | { |
| 6298 | 7446 | $headdata = null; |
| 6299 | 7447 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace()); |
| 6300 | - if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n"); |
|
| 6301 | - if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 6302 | - if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 6303 | - if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 6304 | - if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 6305 | - if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 6306 | - if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n"); |
|
| 6307 | - if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n"); |
|
| 6308 | - if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n"); |
|
| 7448 | + if ($header['SUBJECT']) |
|
| 7449 | + { |
|
| 7450 | + $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n"); |
|
| 7451 | + } |
|
| 7452 | + if ($header['FROM']) |
|
| 7453 | + { |
|
| 7454 | + $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 7455 | + } |
|
| 7456 | + if ($header['SENDER']) |
|
| 7457 | + { |
|
| 7458 | + $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 7459 | + } |
|
| 7460 | + if ($header['TO']) |
|
| 7461 | + { |
|
| 7462 | + $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 7463 | + } |
|
| 7464 | + if ($header['CC']) |
|
| 7465 | + { |
|
| 7466 | + $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 7467 | + } |
|
| 7468 | + if ($header['BCC']) |
|
| 7469 | + { |
|
| 7470 | + $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 7471 | + } |
|
| 7472 | + if ($header['DATE']) |
|
| 7473 | + { |
|
| 7474 | + $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n"); |
|
| 7475 | + } |
|
| 7476 | + if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') |
|
| 7477 | + { |
|
| 7478 | + $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n"); |
|
| 7479 | + } |
|
| 7480 | + if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') |
|
| 7481 | + { |
|
| 7482 | + $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n"); |
|
| 7483 | + } |
|
| 6309 | 7484 | //if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\ |
| 6310 | 7485 | if (!empty($headdata)) |
| 6311 | 7486 | { |
| 6312 | - if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata; |
|
| 6313 | - if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata; |
|
| 7487 | + if (!empty($headline) && $headline != 'SUPPRESS') |
|
| 7488 | + { |
|
| 7489 | + $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata; |
|
| 7490 | + } |
|
| 7491 | + if (empty($headline)) |
|
| 7492 | + { |
|
| 7493 | + $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata; |
|
| 7494 | + } |
|
| 6314 | 7495 | $headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):''); |
| 6315 | 7496 | } |
| 6316 | 7497 | else |
@@ -6344,12 +7525,15 @@ discard block |
||
| 6344 | 7525 | $returnAddr =''; |
| 6345 | 7526 | if (is_array($rfcAddressArray)) |
| 6346 | 7527 | { |
| 6347 | - foreach((array)$rfcAddressArray as $addressData) { |
|
| 7528 | + foreach((array)$rfcAddressArray as $addressData) |
|
| 7529 | + { |
|
| 6348 | 7530 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData)); |
| 6349 | - if($addressData['MAILBOX_NAME'] == 'NIL') { |
|
| 7531 | + if($addressData['MAILBOX_NAME'] == 'NIL') |
|
| 7532 | + { |
|
| 6350 | 7533 | continue; |
| 6351 | 7534 | } |
| 6352 | - if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') { |
|
| 7535 | + if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') |
|
| 7536 | + { |
|
| 6353 | 7537 | continue; |
| 6354 | 7538 | } |
| 6355 | 7539 | if ($addressData['RFC822_EMAIL']) |
@@ -6363,7 +7547,10 @@ discard block |
||
| 6363 | 7547 | } |
| 6364 | 7548 | $addressObject = $addressObjectA[0]; |
| 6365 | 7549 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressObject)); |
| 6366 | - if (!$addressObject->valid) continue; |
|
| 7550 | + if (!$addressObject->valid) |
|
| 7551 | + { |
|
| 7552 | + continue; |
|
| 7553 | + } |
|
| 6367 | 7554 | //$mb =(string)$addressObject->mailbox; |
| 6368 | 7555 | //$h = (string)$addressObject->host; |
| 6369 | 7556 | //$p = (string)$addressObject->personal; |
@@ -6380,7 +7567,10 @@ discard block |
||
| 6380 | 7567 | // do not mess with strings, return them untouched /* ToDo: validate string as Address */ |
| 6381 | 7568 | $rfcAddressArray = self::decode_header($rfcAddressArray,true); |
| 6382 | 7569 | $rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray); |
| 6383 | - if (is_string($rfcAddressArray)) return $rfcAddressArray; |
|
| 7570 | + if (is_string($rfcAddressArray)) |
|
| 7571 | + { |
|
| 7572 | + return $rfcAddressArray; |
|
| 7573 | + } |
|
| 6384 | 7574 | } |
| 6385 | 7575 | return $returnAddr; |
| 6386 | 7576 | } |
@@ -6397,10 +7587,19 @@ discard block |
||
| 6397 | 7587 | { |
| 6398 | 7588 | $mergeobj = new Contacts\Merge(); |
| 6399 | 7589 | |
| 6400 | - if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html'); |
|
| 7590 | + if (empty($mimetype)) |
|
| 7591 | + { |
|
| 7592 | + $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html'); |
|
| 7593 | + } |
|
| 6401 | 7594 | $rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset); |
| 6402 | - if (empty($rv) && !empty($content) && !empty($err)) $rv = $content; |
|
| 6403 | - if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err)); |
|
| 7595 | + if (empty($rv) && !empty($content) && !empty($err)) |
|
| 7596 | + { |
|
| 7597 | + $rv = $content; |
|
| 7598 | + } |
|
| 7599 | + if (!empty($err) && !empty($content) && !empty($ids)) |
|
| 7600 | + { |
|
| 7601 | + error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err)); |
|
| 7602 | + } |
|
| 6404 | 7603 | return $rv; |
| 6405 | 7604 | } |
| 6406 | 7605 | |
@@ -6437,13 +7636,15 @@ discard block |
||
| 6437 | 7636 | settype($bytes, 'integer'); |
| 6438 | 7637 | $bytes /= 10; |
| 6439 | 7638 | } |
| 6440 | - else |
|
| 6441 | - settype($bytes, 'integer'); |
|
| 7639 | + else { |
|
| 7640 | + settype($bytes, 'integer'); |
|
| 7641 | + } |
|
| 6442 | 7642 | |
| 6443 | 7643 | return $bytes . ' ' . $type ; |
| 6444 | 7644 | } |
| 6445 | 7645 | |
| 6446 | - static function detect_qp(&$sting) { |
|
| 7646 | + static function detect_qp(&$sting) |
|
| 7647 | + { |
|
| 6447 | 7648 | $needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/'; |
| 6448 | 7649 | return preg_match("$needle",$string); |
| 6449 | 7650 | } |
@@ -6460,9 +7661,15 @@ discard block |
||
| 6460 | 7661 | */ |
| 6461 | 7662 | static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='') |
| 6462 | 7663 | { |
| 6463 | - if (is_null($_endtime)) $_endtime = microtime(true); |
|
| 7664 | + if (is_null($_endtime)) |
|
| 7665 | + { |
|
| 7666 | + $_endtime = microtime(true); |
|
| 7667 | + } |
|
| 6464 | 7668 | $usagetime = microtime(true) - $_starttime; |
| 6465 | - if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:'')); |
|
| 7669 | + if (self::$debugTimes) |
|
| 7670 | + { |
|
| 7671 | + error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:'')); |
|
| 7672 | + } |
|
| 6466 | 7673 | } |
| 6467 | 7674 | |
| 6468 | 7675 | /** |
@@ -6477,7 +7684,10 @@ discard block |
||
| 6477 | 7684 | */ |
| 6478 | 7685 | static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822') |
| 6479 | 7686 | { |
| 6480 | - if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file']; |
|
| 7687 | + if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') |
|
| 7688 | + { |
|
| 7689 | + return $_formData['file']; |
|
| 7690 | + } |
|
| 6481 | 7691 | |
| 6482 | 7692 | //error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType); |
| 6483 | 7693 | $importfailed = $tmpFileName = false; |
@@ -6526,8 +7736,15 @@ discard block |
||
| 6526 | 7736 | { |
| 6527 | 7737 | $buff = explode('.',$_formData['name']); |
| 6528 | 7738 | $suffix = ''; |
| 6529 | - if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime |
|
| 6530 | - if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix); |
|
| 7739 | + if (is_array($buff)) |
|
| 7740 | + { |
|
| 7741 | + $suffix = array_pop($buff); |
|
| 7742 | + } |
|
| 7743 | + // take the last extension to check with ext2mime |
|
| 7744 | + if (!empty($suffix)) |
|
| 7745 | + { |
|
| 7746 | + $sfxMimeType = MimeMagic::ext2mime($suffix); |
|
| 7747 | + } |
|
| 6531 | 7748 | if (!empty($suffix) && !empty($sfxMimeType) && |
| 6532 | 7749 | (strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType))) |
| 6533 | 7750 | { |
@@ -6575,7 +7792,9 @@ discard block |
||
| 6575 | 7792 | { |
| 6576 | 7793 | rename($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName); |
| 6577 | 7794 | } |
| 6578 | - } else { |
|
| 7795 | + } |
|
| 7796 | + else |
|
| 7797 | + { |
|
| 6579 | 7798 | //error_log("Import of message ".$_formData['file']." failes to meet basic restrictions"); |
| 6580 | 7799 | $importfailed = true; |
| 6581 | 7800 | $alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']); |
@@ -6621,21 +7840,32 @@ discard block |
||
| 6621 | 7840 | if (substr($url, 0, 5) !== 'data:') |
| 6622 | 7841 | { |
| 6623 | 7842 | $filename = basename($url); |
| 6624 | - if (($directory = dirname($url)) == '.') $directory = ''; |
|
| 7843 | + if (($directory = dirname($url)) == '.') |
|
| 7844 | + { |
|
| 7845 | + $directory = ''; |
|
| 7846 | + } |
|
| 6625 | 7847 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
| 6626 | 7848 | $mimeType = MimeMagic::ext2mime($ext); |
| 6627 | - if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } |
|
| 7849 | + if ( strlen($directory) > 1 && substr($directory,-1) != '/') |
|
| 7850 | + { |
|
| 7851 | +$directory .= '/'; } |
|
| 6628 | 7852 | $myUrl = $directory.$filename; |
| 6629 | - if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs) |
|
| 7853 | + if ($myUrl[0]=='/') |
|
| 7854 | + { |
|
| 7855 | + // local path -> we only allow path's that are available via http/https (or vfs) |
|
| 6630 | 7856 | { |
| 6631 | 7857 | $basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']); |
| 6632 | 7858 | } |
| 7859 | + } |
|
| 6633 | 7860 | // use vfs instead of url containing webdav.php |
| 6634 | 7861 | // ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign |
| 6635 | 7862 | // webdav.php urls as vfs |
| 6636 | - if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it. |
|
| 7863 | + if (strpos($myUrl,'/webdav.php') !== false) |
|
| 7864 | + { |
|
| 7865 | + // we have a webdav link, so we build a vfs/sqlfs link of it. |
|
| 6637 | 7866 | { |
| 6638 | 7867 | Vfs::load_wrapper('vfs'); |
| 7868 | + } |
|
| 6639 | 7869 | list(,$myUrl) = explode('/webdav.php',$myUrl,2); |
| 6640 | 7870 | $basedir = 'vfs://default'; |
| 6641 | 7871 | $needTempFile = false; |
@@ -6664,8 +7894,13 @@ discard block |
||
| 6664 | 7894 | } |
| 6665 | 7895 | } |
| 6666 | 7896 | |
| 6667 | - if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; } |
|
| 6668 | - if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl)); |
|
| 7897 | + if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') |
|
| 7898 | + { |
|
| 7899 | +$basedir .= '/'; } |
|
| 7900 | + if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") |
|
| 7901 | + { |
|
| 7902 | + $data = file_get_contents($basedir.urldecode($myUrl)); |
|
| 7903 | + } |
|
| 6669 | 7904 | } |
| 6670 | 7905 | if (substr($url,0,strlen('data:'))=='data:') |
| 6671 | 7906 | { |
@@ -6773,7 +8008,10 @@ discard block |
||
| 6773 | 8008 | $_folder = $this->getSentFolder(); |
| 6774 | 8009 | } |
| 6775 | 8010 | $delimiter = $this->getHierarchyDelimiter(); |
| 6776 | - if($_folder=='INBOX'.$delimiter) $_folder='INBOX'; |
|
| 8011 | + if($_folder=='INBOX'.$delimiter) |
|
| 8012 | + { |
|
| 8013 | + $_folder='INBOX'; |
|
| 8014 | + } |
|
| 6777 | 8015 | if ($importfailed === false) |
| 6778 | 8016 | { |
| 6779 | 8017 | $Subject = $mailObject->getHeader('Subject'); |
@@ -6802,7 +8040,9 @@ discard block |
||
| 6802 | 8040 | //error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val); |
| 6803 | 8041 | if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/ |
| 6804 | 8042 | count($SendAndMergeTocontacts) > 1 && $val && |
| 6805 | - (is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge |
|
| 8043 | + (is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) |
|
| 8044 | + { |
|
| 8045 | + // do the merge |
|
| 6806 | 8046 | { |
| 6807 | 8047 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject)); |
| 6808 | 8048 | |
@@ -6811,6 +8051,7 @@ discard block |
||
| 6811 | 8051 | { |
| 6812 | 8052 | //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)); |
| 6813 | 8053 | $merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset); |
| 8054 | + } |
|
| 6814 | 8055 | $mailObject->addAddress($merged,'',$type); |
| 6815 | 8056 | if($type == 'to') |
| 6816 | 8057 | { |
@@ -6842,9 +8083,15 @@ discard block |
||
| 6842 | 8083 | $mailObject->clearCustomHeaders(); |
| 6843 | 8084 | $mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset)); |
| 6844 | 8085 | //error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType); |
| 6845 | - 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)); |
|
| 8086 | + if($text_body) |
|
| 8087 | + { |
|
| 8088 | + $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); |
|
| 8089 | + } |
|
| 6846 | 8090 | //error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e)); |
| 6847 | - 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)); |
|
| 8091 | + if($html_body) |
|
| 8092 | + { |
|
| 8093 | + $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); |
|
| 8094 | + } |
|
| 6848 | 8095 | |
| 6849 | 8096 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject)); |
| 6850 | 8097 | // set a higher timeout for big messages |
@@ -6859,9 +8106,12 @@ discard block |
||
| 6859 | 8106 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo)); |
| 6860 | 8107 | } |
| 6861 | 8108 | } |
| 6862 | - elseif (!$k) // 1. entry, further entries will fail for apps other then addressbook |
|
| 8109 | + elseif (!$k) |
|
| 8110 | + { |
|
| 8111 | + // 1. entry, further entries will fail for apps other then addressbook |
|
| 6863 | 8112 | { |
| 6864 | 8113 | $openAsDraft = true; |
| 8114 | + } |
|
| 6865 | 8115 | $mailObject->removeHeader('Message-ID'); |
| 6866 | 8116 | $mailObject->removeHeader('Date'); |
| 6867 | 8117 | $mailObject->clearCustomHeaders(); |
@@ -6876,9 +8126,12 @@ discard block |
||
| 6876 | 8126 | |
| 6877 | 8127 | // No addresses from placeholders? Treat it as just a contact ID |
| 6878 | 8128 | if (count($mailObject->getAddresses('to',true)) == 0 && |
| 6879 | - is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge |
|
| 8129 | + is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) |
|
| 8130 | + { |
|
| 8131 | + // do the merge |
|
| 6880 | 8132 | { |
| 6881 | 8133 | $contact = $bo_merge->contacts->read($val); |
| 8134 | + } |
|
| 6882 | 8135 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact)); |
| 6883 | 8136 | $email = ($contact['email'] ? $contact['email'] : $contact['email_home']); |
| 6884 | 8137 | $nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']); |
@@ -6889,9 +8142,15 @@ discard block |
||
| 6889 | 8142 | } |
| 6890 | 8143 | $mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset)); |
| 6891 | 8144 | //error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType); |
| 6892 | - 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)); |
|
| 8145 | + if (!empty($Body)) |
|
| 8146 | + { |
|
| 8147 | + $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); |
|
| 8148 | + } |
|
| 6893 | 8149 | //error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e)); |
| 6894 | - 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)); |
|
| 8150 | + if (!empty($AltBody)) |
|
| 8151 | + { |
|
| 8152 | + $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); |
|
| 8153 | + } |
|
| 6895 | 8154 | $_folder = $this->getDraftFolder(); |
| 6896 | 8155 | } |
| 6897 | 8156 | if ($sendOK || $openAsDraft) |
@@ -6899,11 +8158,15 @@ discard block |
||
| 6899 | 8158 | if ($this->folderExists($_folder,true)) |
| 6900 | 8159 | { |
| 6901 | 8160 | if($this->isSentFolder($_folder)) |
| 6902 | - { |
|
| 8161 | + { |
|
| 6903 | 8162 | $flags = '\\Seen'; |
| 6904 | - } elseif($this->isDraftFolder($_folder)) { |
|
| 8163 | + } |
|
| 8164 | + elseif($this->isDraftFolder($_folder)) |
|
| 8165 | + { |
|
| 6905 | 8166 | $flags = '\\Draft'; |
| 6906 | - } else { |
|
| 8167 | + } |
|
| 8168 | + else |
|
| 8169 | + { |
|
| 6907 | 8170 | $flags = ''; |
| 6908 | 8171 | } |
| 6909 | 8172 | $savefailed = false; |
@@ -6937,7 +8200,10 @@ discard block |
||
| 6937 | 8200 | } |
| 6938 | 8201 | else |
| 6939 | 8202 | { |
| 6940 | - if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details'; |
|
| 8203 | + if (!$openComposeWindow) |
|
| 8204 | + { |
|
| 8205 | + $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details'; |
|
| 8206 | + } |
|
| 6941 | 8207 | } |
| 6942 | 8208 | } |
| 6943 | 8209 | if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow)) |
@@ -6985,7 +8251,10 @@ discard block |
||
| 6985 | 8251 | $tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($tmpFileName); |
| 6986 | 8252 | break; |
| 6987 | 8253 | } |
| 6988 | - if (!isset($message)) $message = fopen($tmpFileName, 'r'); |
|
| 8254 | + if (!isset($message)) |
|
| 8255 | + { |
|
| 8256 | + $message = fopen($tmpFileName, 'r'); |
|
| 8257 | + } |
|
| 6989 | 8258 | |
| 6990 | 8259 | if (!$message) |
| 6991 | 8260 | { |
@@ -7013,7 +8282,8 @@ discard block |
||
| 7013 | 8282 | { |
| 7014 | 8283 | fseek($message, 0, SEEK_SET); |
| 7015 | 8284 | $m = ''; |
| 7016 | - while (!feof($message)) { |
|
| 8285 | + while (!feof($message)) |
|
| 8286 | + { |
|
| 7017 | 8287 | $m .= fread($message, 8192); |
| 7018 | 8288 | } |
| 7019 | 8289 | $message = $m; |
@@ -7035,7 +8305,8 @@ discard block |
||
| 7035 | 8305 | $needsReplacement = $needsFix = true; |
| 7036 | 8306 | } |
| 7037 | 8307 | } |
| 7038 | - if ($needsReplacement) { |
|
| 8308 | + if ($needsReplacement) |
|
| 8309 | + { |
|
| 7039 | 8310 | $headers->removeHeader($header); |
| 7040 | 8311 | $headers->addHeader($header, $value); |
| 7041 | 8312 | } |
@@ -7074,7 +8345,10 @@ discard block |
||
| 7074 | 8345 | (fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192)); |
| 7075 | 8346 | |
| 7076 | 8347 | $length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL); |
| 7077 | - if ($length===false) $length = strlen($start); |
|
| 8348 | + if ($length===false) |
|
| 8349 | + { |
|
| 8350 | + $length = strlen($start); |
|
| 8351 | + } |
|
| 7078 | 8352 | $headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length)); |
| 7079 | 8353 | |
| 7080 | 8354 | foreach($headers->toArray(array('nowrap' => true)) as $header => $value) |
@@ -7109,7 +8383,10 @@ discard block |
||
| 7109 | 8383 | } |
| 7110 | 8384 | else |
| 7111 | 8385 | { |
| 7112 | - if (($type = gettype($message)) == 'object') $type = get_class ($message); |
|
| 8386 | + if (($type = gettype($message)) == 'object') |
|
| 8387 | + { |
|
| 8388 | + $type = get_class ($message); |
|
| 8389 | + } |
|
| 7113 | 8390 | throw new Exception\WrongParameter('Wrong parameter type for message: '.$type); |
| 7114 | 8391 | } |
| 7115 | 8392 | } |
@@ -7133,7 +8410,9 @@ discard block |
||
| 7133 | 8410 | $matches = array(); |
| 7134 | 8411 | preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches); |
| 7135 | 8412 | //error_log(__METHOD__.__LINE__.array2string($matches)); |
| 7136 | - foreach ($matches[0] as &$match) {$match = trim($match,', ');} |
|
| 8413 | + foreach ($matches[0] as &$match) |
|
| 8414 | + { |
|
| 8415 | +$match = trim($match,', ');} |
|
| 7137 | 8416 | $addresses = implode(',',$matches[0]); |
| 7138 | 8417 | //error_log(__METHOD__.__LINE__.array2string($addresses)); |
| 7139 | 8418 | $ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array()); |
@@ -7164,7 +8443,10 @@ discard block |
||
| 7164 | 8443 | } |
| 7165 | 8444 | else |
| 7166 | 8445 | { |
| 7167 | - if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal; |
|
| 8446 | + if ($previousFailed && $remember) |
|
| 8447 | + { |
|
| 8448 | + $adr->personal = $remember. ' ' . $adr->personal; |
|
| 8449 | + } |
|
| 7168 | 8450 | $remember = ''; |
| 7169 | 8451 | $previousFailed=false; |
| 7170 | 8452 | //error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal"); |
@@ -7186,7 +8468,10 @@ discard block |
||
| 7186 | 8468 | { |
| 7187 | 8469 | $acc = Mail\Account::read($this->profileID); |
| 7188 | 8470 | $identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc); |
| 7189 | - if (self::$debug) error_log(__METHOD__.__LINE__.array2string($identity)); |
|
| 8471 | + if (self::$debug) |
|
| 8472 | + { |
|
| 8473 | + error_log(__METHOD__.__LINE__.array2string($identity)); |
|
| 8474 | + } |
|
| 7190 | 8475 | $headers = $this->getMessageHeader($uid, '', 'object', true, $_folder); |
| 7191 | 8476 | |
| 7192 | 8477 | $mdn = new Horde_Mime_Mdn($headers); |