@@ -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 | |
@@ -317,14 +333,20 @@ discard block |
||
| 317 | 333 | } |
| 318 | 334 | catch (\Exception $e) |
| 319 | 335 | { |
| 320 | - if ($_profileID != Mail\Account::get_default_acc_id()) $_profileID = Mail\Account::get_default_acc_id(); |
|
| 336 | + if ($_profileID != Mail\Account::get_default_acc_id()) |
|
| 337 | + { |
|
| 338 | + $_profileID = Mail\Account::get_default_acc_id(); |
|
| 339 | + } |
|
| 321 | 340 | error_log(__METHOD__.__LINE__.' '.$e->getMessage()); |
| 322 | 341 | return false; |
| 323 | 342 | } |
| 324 | 343 | } |
| 325 | 344 | if ($oldProfileID != $_profileID) |
| 326 | 345 | { |
| 327 | - if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID; |
|
| 346 | + if ($oldProfileID && $_profileID==0) |
|
| 347 | + { |
|
| 348 | + $_profileID = $oldProfileID; |
|
| 349 | + } |
|
| 328 | 350 | $GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user'); |
| 329 | 351 | // save prefs |
| 330 | 352 | $GLOBALS['egw']->preferences->save_repository(true); |
@@ -354,11 +376,17 @@ discard block |
||
| 354 | 376 | { |
| 355 | 377 | return $_acc_id; |
| 356 | 378 | } |
| 357 | - if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!"); |
|
| 379 | + if (self::$debug) |
|
| 380 | + { |
|
| 381 | + error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!"); |
|
| 382 | + } |
|
| 358 | 383 | } |
| 359 | 384 | catch (\Exception $e) { |
| 360 | 385 | unset($e); |
| 361 | - if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT found!"); |
|
| 386 | + if (self::$debug) |
|
| 387 | + { |
|
| 388 | + error_log(__METHOD__."($_acc_id) account NOT found!"); |
|
| 389 | + } |
|
| 362 | 390 | } |
| 363 | 391 | } |
| 364 | 392 | // no account specified or specified account not found or not valid |
@@ -367,11 +395,17 @@ discard block |
||
| 367 | 395 | { |
| 368 | 396 | if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap()) |
| 369 | 397 | { |
| 370 | - if (self::$debug && $_acc_id) error_log(__METHOD__."($_acc_id) using $acc_id instead"); |
|
| 398 | + if (self::$debug && $_acc_id) |
|
| 399 | + { |
|
| 400 | + error_log(__METHOD__."($_acc_id) using $acc_id instead"); |
|
| 401 | + } |
|
| 371 | 402 | return $acc_id; |
| 372 | 403 | } |
| 373 | 404 | } |
| 374 | - if (self::$debug) error_log(__METHOD__."($_acc_id) NO valid account found!"); |
|
| 405 | + if (self::$debug) |
|
| 406 | + { |
|
| 407 | + error_log(__METHOD__."($_acc_id) NO valid account found!"); |
|
| 408 | + } |
|
| 375 | 409 | return 0; |
| 376 | 410 | } |
| 377 | 411 | |
@@ -387,10 +421,19 @@ discard block |
||
| 387 | 421 | */ |
| 388 | 422 | private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null) |
| 389 | 423 | { |
| 390 | - if (is_null($_reuseCache)) $_reuseCache = $_restoreSession; |
|
| 391 | - if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset; |
|
| 424 | + if (is_null($_reuseCache)) |
|
| 425 | + { |
|
| 426 | + $_reuseCache = $_restoreSession; |
|
| 427 | + } |
|
| 428 | + if (!empty($_displayCharset)) |
|
| 429 | + { |
|
| 430 | + self::$displayCharset = $_displayCharset; |
|
| 431 | + } |
|
| 392 | 432 | // not nummeric, we assume we only want an empty class object |
| 393 | - if (!is_numeric($_profileID)) return true; |
|
| 433 | + if (!is_numeric($_profileID)) |
|
| 434 | + { |
|
| 435 | + return true; |
|
| 436 | + } |
|
| 394 | 437 | if ($_restoreSession) |
| 395 | 438 | { |
| 396 | 439 | //error_log(__METHOD__." Session restore ".function_backtrace()); |
@@ -405,7 +448,10 @@ discard block |
||
| 405 | 448 | $firstMessage = $this->sessionData['previewMessage']; |
| 406 | 449 | $this->sessionData = array(); |
| 407 | 450 | } |
| 408 | - if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache); |
|
| 451 | + if (!$_reuseCache) |
|
| 452 | + { |
|
| 453 | + $this->forcePrefReload($_profileID,!$_reuseCache); |
|
| 454 | + } |
|
| 409 | 455 | try |
| 410 | 456 | { |
| 411 | 457 | $this->profileID = self::validateProfileID($_profileID); |
@@ -429,7 +475,10 @@ discard block |
||
| 429 | 475 | $_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId; |
| 430 | 476 | } |
| 431 | 477 | |
| 432 | - if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail'); |
|
| 478 | + if (is_null(self::$mailConfig)) |
|
| 479 | + { |
|
| 480 | + self::$mailConfig = Config::read('mail'); |
|
| 481 | + } |
|
| 433 | 482 | } |
| 434 | 483 | |
| 435 | 484 | /** |
@@ -458,7 +507,10 @@ discard block |
||
| 458 | 507 | // unset the mail_preferences session object, to force the reload/rebuild |
| 459 | 508 | Cache::setSession('mail','mail_preferences',serialize(array())); |
| 460 | 509 | Cache::setSession('emailadmin','session_data',serialize(array())); |
| 461 | - if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id); |
|
| 510 | + if ($_resetFolderObjects) |
|
| 511 | + { |
|
| 512 | + self::resetFolderObjectCache($_profile_id); |
|
| 513 | + } |
|
| 462 | 514 | } |
| 463 | 515 | |
| 464 | 516 | /** |
@@ -468,7 +520,10 @@ discard block |
||
| 468 | 520 | { |
| 469 | 521 | $this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1); |
| 470 | 522 | self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10); |
| 471 | - if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID]; |
|
| 523 | + if (!empty(self::$activeFolderCache[$this->profileID])) |
|
| 524 | + { |
|
| 525 | + $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID]; |
|
| 526 | + } |
|
| 472 | 527 | } |
| 473 | 528 | |
| 474 | 529 | /** |
@@ -477,7 +532,10 @@ discard block |
||
| 477 | 532 | function saveSessionData() |
| 478 | 533 | { |
| 479 | 534 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData))); |
| 480 | - if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox']; |
|
| 535 | + if (!empty($this->sessionData['mailbox'])) |
|
| 536 | + { |
|
| 537 | + self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox']; |
|
| 538 | + } |
|
| 481 | 539 | if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache)) |
| 482 | 540 | { |
| 483 | 541 | Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10); |
@@ -498,8 +556,14 @@ discard block |
||
| 498 | 556 | */ |
| 499 | 557 | static function unsetCachedObjects($_profileID=null) |
| 500 | 558 | { |
| 501 | - if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id(); |
|
| 502 | - if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id']; |
|
| 559 | + if (is_null($_profileID)) |
|
| 560 | + { |
|
| 561 | + $_profileID = Mail\Account::get_default_acc_id(); |
|
| 562 | + } |
|
| 563 | + if (is_array($_profileID) && $_profileID['account_id']) |
|
| 564 | + { |
|
| 565 | + $account_id = $_profileID['account_id']; |
|
| 566 | + } |
|
| 503 | 567 | //error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace()); |
| 504 | 568 | if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false))) |
| 505 | 569 | { |
@@ -532,7 +596,10 @@ discard block |
||
| 532 | 596 | Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1); |
| 533 | 597 | } |
| 534 | 598 | |
| 535 | - if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]); |
|
| 599 | + if (isset(self::$instances[$_profileID])) |
|
| 600 | + { |
|
| 601 | + unset(self::$instances[$_profileID]); |
|
| 602 | + } |
|
| 536 | 603 | } |
| 537 | 604 | if (is_array($_profileID) && $_profileID['location'] == 'clear_cache') |
| 538 | 605 | { |
@@ -561,7 +628,10 @@ discard block |
||
| 561 | 628 | static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null) |
| 562 | 629 | { |
| 563 | 630 | //error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id)); |
| 564 | - if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id']; |
|
| 631 | + if (is_null($account_id)) |
|
| 632 | + { |
|
| 633 | + $account_id = $GLOBALS['egw_info']['user']['account_id']; |
|
| 634 | + } |
|
| 565 | 635 | if (is_array($_ImapServerId)) |
| 566 | 636 | { |
| 567 | 637 | // called via hook |
@@ -600,7 +670,10 @@ discard block |
||
| 600 | 670 | static function resetFolderObjectCache($_ImapServerId=null,$account_id=null) |
| 601 | 671 | { |
| 602 | 672 | //error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace()); |
| 603 | - if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id']; |
|
| 673 | + if (is_null($account_id)) |
|
| 674 | + { |
|
| 675 | + $account_id = $GLOBALS['egw_info']['user']['account_id']; |
|
| 676 | + } |
|
| 604 | 677 | // on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId |
| 605 | 678 | // or treat it as not given. we try that path |
| 606 | 679 | if (is_null($_ImapServerId)||is_array($_ImapServerId)) |
@@ -674,10 +747,14 @@ discard block |
||
| 674 | 747 | |
| 675 | 748 | $userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']); |
| 676 | 749 | |
| 677 | - foreach($identities as $ik => $ident) { |
|
| 750 | + foreach($identities as $ik => $ident) |
|
| 751 | + { |
|
| 678 | 752 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident)); |
| 679 | 753 | $identity = Mail\Account::read_identity($ik); |
| 680 | - if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname']; |
|
| 754 | + if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) |
|
| 755 | + { |
|
| 756 | + $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname']; |
|
| 757 | + } |
|
| 681 | 758 | } |
| 682 | 759 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses)); |
| 683 | 760 | return $userEMailAdresses; |
@@ -695,13 +772,20 @@ discard block |
||
| 695 | 772 | foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name) |
| 696 | 773 | { |
| 697 | 774 | $acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null)); |
| 698 | - 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']); |
|
| 775 | + if (!$resolve_placeholders) |
|
| 776 | + { |
|
| 777 | + $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']); |
|
| 778 | + } |
|
| 699 | 779 | |
| 700 | - foreach(Mail\Account::identities($acc) as $ik => $ident) { |
|
| 780 | + foreach(Mail\Account::identities($acc) as $ik => $ident) |
|
| 781 | + { |
|
| 701 | 782 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident)); |
| 702 | 783 | $identity = Mail\Account::read_identity($ik,$resolve_placeholders); |
| 703 | 784 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity)); |
| 704 | - 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']); |
|
| 785 | + if (!isset($userEMailAdresses[$identity['ident_id']])) |
|
| 786 | + { |
|
| 787 | + $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']); |
|
| 788 | + } |
|
| 705 | 789 | } |
| 706 | 790 | } |
| 707 | 791 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses)); |
@@ -721,12 +805,16 @@ discard block |
||
| 721 | 805 | $account = Mail\Account::read($account); |
| 722 | 806 | } |
| 723 | 807 | $userEMailAdresses = array(); |
| 724 | - foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) { |
|
| 808 | + foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) |
|
| 809 | + { |
|
| 725 | 810 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident)); |
| 726 | 811 | $identity = Mail\Account::read_identity($ik,true,null,$account); |
| 727 | 812 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity)); |
| 728 | 813 | // standardIdentity has ident_id==acc_id (as it is done within account->identities) |
| 729 | - if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id']; |
|
| 814 | + if (empty($identity['ident_id'])) |
|
| 815 | + { |
|
| 816 | + $identity['ident_id'] = $identity['acc_id']; |
|
| 817 | + } |
|
| 730 | 818 | if (!isset($userEMailAdresses[$identity['ident_id']])) |
| 731 | 819 | { |
| 732 | 820 | $userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$identity['acc_id'], |
@@ -769,15 +857,25 @@ discard block |
||
| 769 | 857 | // account select box |
| 770 | 858 | $selectedID = $this->profileID; |
| 771 | 859 | $allAccountData = Mail\Account::search($only_current_user=true, false, null); |
| 772 | - if ($allAccountData) { |
|
| 860 | + if ($allAccountData) |
|
| 861 | + { |
|
| 773 | 862 | $rememberFirst=$selectedFound=null; |
| 774 | 863 | foreach ($allAccountData as $tmpkey => $icServers) |
| 775 | 864 | { |
| 776 | - if (is_null($rememberFirst)) $rememberFirst = $tmpkey; |
|
| 777 | - if ($tmpkey == $selectedID) $selectedFound=true; |
|
| 865 | + if (is_null($rememberFirst)) |
|
| 866 | + { |
|
| 867 | + $rememberFirst = $tmpkey; |
|
| 868 | + } |
|
| 869 | + if ($tmpkey == $selectedID) |
|
| 870 | + { |
|
| 871 | + $selectedFound=true; |
|
| 872 | + } |
|
| 778 | 873 | //error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host)); |
| 779 | 874 | $host = $icServers->acc_imap_host; |
| 780 | - if (empty($host)) continue; |
|
| 875 | + if (empty($host)) |
|
| 876 | + { |
|
| 877 | + continue; |
|
| 878 | + } |
|
| 781 | 879 | $identities[$icServers->acc_id] = $icServers['ident_realname'].' '.$icServers['ident_org'].' <'.$icServers['ident_email'].'>'; |
| 782 | 880 | //error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id])); |
| 783 | 881 | } |
@@ -837,7 +935,10 @@ discard block |
||
| 837 | 935 | */ |
| 838 | 936 | function reopen($_foldername) |
| 839 | 937 | { |
| 840 | - if (self::$debugTimes) $starttime = microtime (true); |
|
| 938 | + if (self::$debugTimes) |
|
| 939 | + { |
|
| 940 | + $starttime = microtime (true); |
|
| 941 | + } |
|
| 841 | 942 | |
| 842 | 943 | //error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace()); |
| 843 | 944 | // TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of |
@@ -847,12 +948,16 @@ discard block |
||
| 847 | 948 | //{ |
| 848 | 949 | //error_log( __METHOD__.' ('.__LINE__.') '." $_foldername ".function_backtrace()); |
| 849 | 950 | //error_log(__METHOD__.' ('.__LINE__.') '.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true)); |
| 850 | - if ($this->folderIsSelectable($_foldername)) { |
|
| 951 | + if ($this->folderIsSelectable($_foldername)) |
|
| 952 | + { |
|
| 851 | 953 | $this->icServer->openMailbox($_foldername); |
| 852 | 954 | } |
| 853 | 955 | $folderOpened = $_foldername; |
| 854 | 956 | //} |
| 855 | - if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') '); |
|
| 957 | + if (self::$debugTimes) |
|
| 958 | + { |
|
| 959 | + self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') '); |
|
| 960 | + } |
|
| 856 | 961 | } |
| 857 | 962 | |
| 858 | 963 | |
@@ -867,13 +972,22 @@ discard block |
||
| 867 | 972 | { |
| 868 | 973 | //error_log( "-------------------------->open connection ".function_backtrace()); |
| 869 | 974 | //error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer)); |
| 870 | - if (self::$debugTimes) $starttime = microtime (true); |
|
| 975 | + if (self::$debugTimes) |
|
| 976 | + { |
|
| 977 | + $starttime = microtime (true); |
|
| 978 | + } |
|
| 871 | 979 | $mailbox=null; |
| 872 | 980 | try |
| 873 | 981 | { |
| 874 | - if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox']; |
|
| 875 | - if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox(); |
|
| 876 | -/* |
|
| 982 | + if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) |
|
| 983 | + { |
|
| 984 | + $mailbox = $this->sessionData['mailbox']; |
|
| 985 | + } |
|
| 986 | + if (empty($mailbox)) |
|
| 987 | + { |
|
| 988 | + $mailbox = $this->icServer->getCurrentMailbox(); |
|
| 989 | + } |
|
| 990 | + /* |
|
| 877 | 991 | if (isset(Mail\Imap::$supports_keywords[$_icServerID])) |
| 878 | 992 | { |
| 879 | 993 | $this->icServer->openMailbox($mailbox); |
@@ -898,7 +1012,10 @@ discard block |
||
| 898 | 1012 | error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage()); |
| 899 | 1013 | throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage()); |
| 900 | 1014 | } |
| 901 | - if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') '); |
|
| 1015 | + if (self::$debugTimes) |
|
| 1016 | + { |
|
| 1017 | + self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') '); |
|
| 1018 | + } |
|
| 902 | 1019 | } |
| 903 | 1020 | |
| 904 | 1021 | /** |
@@ -910,7 +1027,10 @@ discard block |
||
| 910 | 1027 | function getQuotaRoot() |
| 911 | 1028 | { |
| 912 | 1029 | static $quota; |
| 913 | - if (isset($quota)) return $quota; |
|
| 1030 | + if (isset($quota)) |
|
| 1031 | + { |
|
| 1032 | + return $quota; |
|
| 1033 | + } |
|
| 914 | 1034 | if (isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID])) |
| 915 | 1035 | { |
| 916 | 1036 | // something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request |
@@ -919,7 +1039,8 @@ discard block |
||
| 919 | 1039 | try |
| 920 | 1040 | { |
| 921 | 1041 | $this->icServer->getCurrentMailbox(); |
| 922 | - if(!$this->icServer->hasCapability('QUOTA')) { |
|
| 1042 | + if(!$this->icServer->hasCapability('QUOTA')) |
|
| 1043 | + { |
|
| 923 | 1044 | $quota = false; |
| 924 | 1045 | return false; |
| 925 | 1046 | } |
@@ -937,12 +1058,15 @@ discard block |
||
| 937 | 1058 | } |
| 938 | 1059 | } |
| 939 | 1060 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota)); |
| 940 | - if(is_array($quota)) { |
|
| 1061 | + if(is_array($quota)) |
|
| 1062 | + { |
|
| 941 | 1063 | $quota = array( |
| 942 | 1064 | 'usage' => $quota['USED'], |
| 943 | 1065 | 'limit' => $quota['QMAX'], |
| 944 | 1066 | ); |
| 945 | - } else { |
|
| 1067 | + } |
|
| 1068 | + else |
|
| 1069 | + { |
|
| 946 | 1070 | $quota = false; |
| 947 | 1071 | } |
| 948 | 1072 | return $quota; |
@@ -958,7 +1082,11 @@ discard block |
||
| 958 | 1082 | static function getTimeOut($_use='IMAP') |
| 959 | 1083 | { |
| 960 | 1084 | $timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout']; |
| 961 | - if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value |
|
| 1085 | + if (empty($timeout)) |
|
| 1086 | + { |
|
| 1087 | + $timeout = ($_use=='SIEVE'?10:20); |
|
| 1088 | + } |
|
| 1089 | + // this is the default value |
|
| 962 | 1090 | return $timeout; |
| 963 | 1091 | } |
| 964 | 1092 | |
@@ -976,9 +1104,13 @@ discard block |
||
| 976 | 1104 | $foldersNameSpace = array(); |
| 977 | 1105 | $delimiter = $this->getHierarchyDelimiter(); |
| 978 | 1106 | // TODO: cache by $this->icServer->ImapServerId |
| 979 | - if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray(); |
|
| 1107 | + if (is_null($nameSpace)) |
|
| 1108 | + { |
|
| 1109 | + $nameSpace = $this->icServer->getNameSpaceArray(); |
|
| 1110 | + } |
|
| 980 | 1111 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace)); |
| 981 | - if (is_array($nameSpace)) { |
|
| 1112 | + if (is_array($nameSpace)) |
|
| 1113 | + { |
|
| 982 | 1114 | foreach($nameSpace as $type => $singleNameSpaceArray) |
| 983 | 1115 | { |
| 984 | 1116 | foreach ($singleNameSpaceArray as $singleNameSpace) |
@@ -995,7 +1127,9 @@ discard block |
||
| 995 | 1127 | $_foldersNameSpace['prefix_present'] = 'forced'; |
| 996 | 1128 | // uw-imap server with mailbox prefix or dovecot maybe |
| 997 | 1129 | $_foldersNameSpace['prefix'] = 'mail'; |
| 998 | - } else { |
|
| 1130 | + } |
|
| 1131 | + else |
|
| 1132 | + { |
|
| 999 | 1133 | $_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']); |
| 1000 | 1134 | $_foldersNameSpace['prefix'] = $singleNameSpace['name']; |
| 1001 | 1135 | } |
@@ -1022,7 +1156,10 @@ discard block |
||
| 1022 | 1156 | foreach($nameSpace as &$singleNameSpace) |
| 1023 | 1157 | { |
| 1024 | 1158 | //if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix']; |
| 1025 | - if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix']; |
|
| 1159 | + if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) |
|
| 1160 | + { |
|
| 1161 | + return $singleNameSpace['prefix']; |
|
| 1162 | + } |
|
| 1026 | 1163 | } |
| 1027 | 1164 | return ""; |
| 1028 | 1165 | } |
@@ -1036,8 +1173,14 @@ discard block |
||
| 1036 | 1173 | function getHierarchyDelimiter($_useCache=true) |
| 1037 | 1174 | { |
| 1038 | 1175 | static $HierarchyDelimiter = null; |
| 1039 | - if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5); |
|
| 1040 | - if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]); |
|
| 1176 | + if (is_null($HierarchyDelimiter)) |
|
| 1177 | + { |
|
| 1178 | + $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5); |
|
| 1179 | + } |
|
| 1180 | + if ($_useCache===false) |
|
| 1181 | + { |
|
| 1182 | + unset($HierarchyDelimiter[$this->icServer->ImapServerId]); |
|
| 1183 | + } |
|
| 1041 | 1184 | if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId])) |
| 1042 | 1185 | { |
| 1043 | 1186 | return $HierarchyDelimiter[$this->icServer->ImapServerId]; |
@@ -1071,14 +1214,19 @@ discard block |
||
| 1071 | 1214 | { |
| 1072 | 1215 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected); |
| 1073 | 1216 | static $_specialUseFolders = null; |
| 1074 | - 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); |
|
| 1217 | + if (is_null($_specialUseFolders)||empty($_specialUseFolders)) |
|
| 1218 | + { |
|
| 1219 | + $_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5); |
|
| 1220 | + } |
|
| 1075 | 1221 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash)); |
| 1076 | 1222 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent)); |
| 1077 | 1223 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft)); |
| 1078 | 1224 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_template)); |
| 1079 | 1225 | self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId]; |
| 1080 | 1226 | if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId])) |
| 1081 | - return $_specialUseFolders[$this->icServer->ImapServerId]; |
|
| 1227 | + { |
|
| 1228 | + return $_specialUseFolders[$this->icServer->ImapServerId]; |
|
| 1229 | + } |
|
| 1082 | 1230 | $_specialUseFolders[$this->icServer->ImapServerId]=array(); |
| 1083 | 1231 | //if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash])) |
| 1084 | 1232 | $_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash'; |
@@ -1106,7 +1254,8 @@ discard block |
||
| 1106 | 1254 | function folderIsSelectable($folderToSelect) |
| 1107 | 1255 | { |
| 1108 | 1256 | $retval = true; |
| 1109 | - if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) { |
|
| 1257 | + if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) |
|
| 1258 | + { |
|
| 1110 | 1259 | if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false) |
| 1111 | 1260 | { |
| 1112 | 1261 | $retval = false; |
@@ -1159,7 +1308,10 @@ discard block |
||
| 1159 | 1308 | */ |
| 1160 | 1309 | function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true) |
| 1161 | 1310 | { |
| 1162 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly"); |
|
| 1311 | + if (self::$debug) |
|
| 1312 | + { |
|
| 1313 | + error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly"); |
|
| 1314 | + } |
|
| 1163 | 1315 | if (!is_string($_folderName) || empty($_folderName)||(isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID]))) |
| 1164 | 1316 | { |
| 1165 | 1317 | // something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request |
@@ -1171,7 +1323,10 @@ discard block |
||
| 1171 | 1323 | { |
| 1172 | 1324 | $folderInfoCache = $folderBasicInfo[$this->profileID]; |
| 1173 | 1325 | } |
| 1174 | - if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName]; |
|
| 1326 | + if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) |
|
| 1327 | + { |
|
| 1328 | + return $folderInfoCache[$_folderName]; |
|
| 1329 | + } |
|
| 1175 | 1330 | $retValue = array(); |
| 1176 | 1331 | $retValue['subscribed'] = false; |
| 1177 | 1332 | /* |
@@ -1200,7 +1355,10 @@ discard block |
||
| 1200 | 1355 | if (is_array($ret)) |
| 1201 | 1356 | { |
| 1202 | 1357 | $retkeys = array_keys($ret); |
| 1203 | - if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]]; |
|
| 1358 | + if ($retkeys[0]==$_folderName) |
|
| 1359 | + { |
|
| 1360 | + $folderInfoCache[$_folderName] = $ret[$retkeys[0]]; |
|
| 1361 | + } |
|
| 1204 | 1362 | } |
| 1205 | 1363 | else |
| 1206 | 1364 | { |
@@ -1209,7 +1367,8 @@ discard block |
||
| 1209 | 1367 | } |
| 1210 | 1368 | $folderInfo = $folderInfoCache[$_folderName]; |
| 1211 | 1369 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace()); |
| 1212 | - if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) { |
|
| 1370 | + if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) |
|
| 1371 | + { |
|
| 1213 | 1372 | try |
| 1214 | 1373 | { |
| 1215 | 1374 | $folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache); |
@@ -1244,7 +1403,8 @@ discard block |
||
| 1244 | 1403 | $retValue['shortName'] = array_pop($shortNameParts); |
| 1245 | 1404 | $retValue['displayName'] = $_folderName; |
| 1246 | 1405 | $retValue['shortDisplayName'] = $retValue['shortName']; |
| 1247 | - if(strtoupper($retValue['shortName']) == 'INBOX') { |
|
| 1406 | + if(strtoupper($retValue['shortName']) == 'INBOX') |
|
| 1407 | + { |
|
| 1248 | 1408 | $retValue['displayName'] = lang('INBOX'); |
| 1249 | 1409 | $retValue['shortDisplayName'] = lang('INBOX'); |
| 1250 | 1410 | } |
@@ -1253,7 +1413,10 @@ discard block |
||
| 1253 | 1413 | { |
| 1254 | 1414 | $retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']); |
| 1255 | 1415 | } |
| 1256 | - if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue; |
|
| 1416 | + if ($folderInfo) |
|
| 1417 | + { |
|
| 1418 | + $folderBasicInfo[$this->profileID][$_folderName]=$retValue; |
|
| 1419 | + } |
|
| 1257 | 1420 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes'])); |
| 1258 | 1421 | if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false)) |
| 1259 | 1422 | { |
@@ -1265,24 +1428,34 @@ discard block |
||
| 1265 | 1428 | static $subscribedFolders = null; |
| 1266 | 1429 | static $nameSpace = null; |
| 1267 | 1430 | static $prefix = null; |
| 1268 | - if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces(); |
|
| 1431 | + if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) |
|
| 1432 | + { |
|
| 1433 | + $nameSpace[$this->profileID] = $this->_getNameSpaces(); |
|
| 1434 | + } |
|
| 1269 | 1435 | if (!empty($nameSpace[$this->profileID])) |
| 1270 | 1436 | { |
| 1271 | 1437 | $nsNoPersonal=array(); |
| 1272 | 1438 | foreach($nameSpace[$this->profileID] as &$ns) |
| 1273 | 1439 | { |
| 1274 | - if ($ns['type']!='personal') $nsNoPersonal[]=$ns; |
|
| 1440 | + if ($ns['type']!='personal') |
|
| 1441 | + { |
|
| 1442 | + $nsNoPersonal[]=$ns; |
|
| 1443 | + } |
|
| 1275 | 1444 | } |
| 1276 | 1445 | $nameSpace[$this->profileID]=$nsNoPersonal; |
| 1277 | 1446 | } |
| 1278 | - if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName); |
|
| 1447 | + if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) |
|
| 1448 | + { |
|
| 1449 | + $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName); |
|
| 1450 | + } |
|
| 1279 | 1451 | |
| 1280 | 1452 | if ($fetchSubscribedInfo && is_null($subscribedFolders) || empty($subscribedFolders[$this->profileID])) |
| 1281 | 1453 | { |
| 1282 | 1454 | $subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes(); |
| 1283 | 1455 | } |
| 1284 | 1456 | |
| 1285 | - if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) { |
|
| 1457 | + if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) |
|
| 1458 | + { |
|
| 1286 | 1459 | $retValue['subscribed'] = true; |
| 1287 | 1460 | } |
| 1288 | 1461 | |
@@ -1301,8 +1474,7 @@ discard block |
||
| 1301 | 1474 | (isset($this->mailPreferences['trustServersUnseenInfo']) && |
| 1302 | 1475 | $this->mailPreferences['trustServersUnseenInfo']==2 && |
| 1303 | 1476 | $prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false) |
| 1304 | - ) |
|
| 1305 | - { |
|
| 1477 | + ) { |
|
| 1306 | 1478 | //error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']); |
| 1307 | 1479 | // we filter for the combined status of unseen and undeleted, as this is what we show in list |
| 1308 | 1480 | try |
@@ -1314,13 +1486,19 @@ discard block |
||
| 1314 | 1486 | } |
| 1315 | 1487 | catch (\Exception $ee) |
| 1316 | 1488 | { |
| 1317 | - if (self::$debug) error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested."); |
|
| 1489 | + if (self::$debug) |
|
| 1490 | + { |
|
| 1491 | + error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested."); |
|
| 1492 | + } |
|
| 1318 | 1493 | } |
| 1319 | 1494 | } |
| 1320 | 1495 | } |
| 1321 | 1496 | catch (\Exception $e) |
| 1322 | 1497 | { |
| 1323 | - if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true)); |
|
| 1498 | + if (self::$debug) |
|
| 1499 | + { |
|
| 1500 | + error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true)); |
|
| 1501 | + } |
|
| 1324 | 1502 | } |
| 1325 | 1503 | |
| 1326 | 1504 | return $retValue; |
@@ -1345,8 +1523,14 @@ discard block |
||
| 1345 | 1523 | function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false) |
| 1346 | 1524 | { |
| 1347 | 1525 | //self::$debug=true; |
| 1348 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace()); |
|
| 1349 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly"); |
|
| 1526 | + if (self::$debug) |
|
| 1527 | + { |
|
| 1528 | + error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace()); |
|
| 1529 | + } |
|
| 1530 | + if (self::$debug) |
|
| 1531 | + { |
|
| 1532 | + error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly"); |
|
| 1533 | + } |
|
| 1350 | 1534 | $reverse = (bool)$_reverse; |
| 1351 | 1535 | // get the list of messages to fetch |
| 1352 | 1536 | $this->reopen($_folderName); |
@@ -1367,21 +1551,34 @@ discard block |
||
| 1367 | 1551 | //$_filter['range'] ="$start:$end"; |
| 1368 | 1552 | //$_filter['range'] ="$_startMessage:*"; |
| 1369 | 1553 | } |
| 1370 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid"); |
|
| 1371 | - if (self::$debug||self::$debugTimes) $starttime = microtime (true); |
|
| 1554 | + if (self::$debug) |
|
| 1555 | + { |
|
| 1556 | + error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid"); |
|
| 1557 | + } |
|
| 1558 | + if (self::$debug||self::$debugTimes) |
|
| 1559 | + { |
|
| 1560 | + $starttime = microtime (true); |
|
| 1561 | + } |
|
| 1372 | 1562 | //see this example below for a 12 week datefilter (since) |
| 1373 | 1563 | //$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12))); |
| 1374 | 1564 | $_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult); |
| 1375 | 1565 | $sortResult = $_sortResult['match']->ids; |
| 1376 | 1566 | //$modseq = $_sortResult['modseq']; |
| 1377 | 1567 | //error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq); |
| 1378 | - if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') '); |
|
| 1568 | + if (self::$debug||self::$debugTimes) |
|
| 1569 | + { |
|
| 1570 | + self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') '); |
|
| 1571 | + } |
|
| 1379 | 1572 | |
| 1380 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult)); |
|
| 1573 | + if (self::$debug) |
|
| 1574 | + { |
|
| 1575 | + error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult)); |
|
| 1576 | + } |
|
| 1381 | 1577 | #$this->icServer->setDebug(false); |
| 1382 | 1578 | #print "</pre>"; |
| 1383 | 1579 | // nothing found |
| 1384 | - if(!is_array($sortResult) || empty($sortResult)) { |
|
| 1580 | + if(!is_array($sortResult) || empty($sortResult)) |
|
| 1581 | + { |
|
| 1385 | 1582 | $retValue = array(); |
| 1386 | 1583 | $retValue['info']['total'] = 0; |
| 1387 | 1584 | $retValue['info']['first'] = 0; |
@@ -1393,7 +1590,8 @@ discard block |
||
| 1393 | 1590 | #_debug_array($sortResult); |
| 1394 | 1591 | #_debug_array(array_slice($sortResult, -5, -2)); |
| 1395 | 1592 | //error_log("REVERSE: $reverse"); |
| 1396 | - if($reverse === true) { |
|
| 1593 | + if($reverse === true) |
|
| 1594 | + { |
|
| 1397 | 1595 | if ($_startMessage<=$total) |
| 1398 | 1596 | { |
| 1399 | 1597 | $startMessage = $_startMessage-1; |
@@ -1405,7 +1603,10 @@ discard block |
||
| 1405 | 1603 | { |
| 1406 | 1604 | $numberOfMessages = $total%$_numberOfMessages; |
| 1407 | 1605 | //$numberOfMessages = abs($_startMessage-$total-1); |
| 1408 | - if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages; |
|
| 1606 | + if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) |
|
| 1607 | + { |
|
| 1608 | + $_numberOfMessages = $numberOfMessages; |
|
| 1609 | + } |
|
| 1409 | 1610 | //error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total); |
| 1410 | 1611 | } |
| 1411 | 1612 | $startMessage=($total-$_numberOfMessages)-1; |
@@ -1419,19 +1620,36 @@ discard block |
||
| 1419 | 1620 | //$retValue['info']['first'] = $startMessage; |
| 1420 | 1621 | //$retValue['info']['last'] = $total; |
| 1421 | 1622 | } |
| 1422 | - if($startMessage > 0) { |
|
| 1423 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult)); |
|
| 1623 | + if($startMessage > 0) |
|
| 1624 | + { |
|
| 1625 | + if (self::$debug) |
|
| 1626 | + { |
|
| 1627 | + error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult)); |
|
| 1628 | + } |
|
| 1424 | 1629 | $sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage); |
| 1425 | - } else { |
|
| 1426 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult)); |
|
| 1630 | + } |
|
| 1631 | + else |
|
| 1632 | + { |
|
| 1633 | + if (self::$debug) |
|
| 1634 | + { |
|
| 1635 | + error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult)); |
|
| 1636 | + } |
|
| 1427 | 1637 | $sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1))); |
| 1428 | 1638 | } |
| 1429 | 1639 | $sortResult = array_reverse($sortResult); |
| 1430 | - } else { |
|
| 1431 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult)); |
|
| 1640 | + } |
|
| 1641 | + else |
|
| 1642 | + { |
|
| 1643 | + if (self::$debug) |
|
| 1644 | + { |
|
| 1645 | + error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult)); |
|
| 1646 | + } |
|
| 1432 | 1647 | $sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages); |
| 1433 | 1648 | } |
| 1434 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult)); |
|
| 1649 | + if (self::$debug) |
|
| 1650 | + { |
|
| 1651 | + error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult)); |
|
| 1652 | + } |
|
| 1435 | 1653 | } |
| 1436 | 1654 | else |
| 1437 | 1655 | { |
@@ -1440,7 +1658,10 @@ discard block |
||
| 1440 | 1658 | |
| 1441 | 1659 | |
| 1442 | 1660 | // fetch the data for the selected messages |
| 1443 | - if (self::$debug||self::$debugTimes) $starttime = microtime(true); |
|
| 1661 | + if (self::$debug||self::$debugTimes) |
|
| 1662 | + { |
|
| 1663 | + $starttime = microtime(true); |
|
| 1664 | + } |
|
| 1444 | 1665 | try |
| 1445 | 1666 | { |
| 1446 | 1667 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
@@ -1464,7 +1685,10 @@ discard block |
||
| 1464 | 1685 | $fquery->flags(); |
| 1465 | 1686 | $fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time |
| 1466 | 1687 | // if $_fetchPreviews is activated fetch part of the messages too |
| 1467 | - if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0)); |
|
| 1688 | + if ($_fetchPreviews) |
|
| 1689 | + { |
|
| 1690 | + $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0)); |
|
| 1691 | + } |
|
| 1468 | 1692 | $headersNew = $this->icServer->fetch($_folderName, $fquery, array( |
| 1469 | 1693 | 'ids' => $uidsToFetch, |
| 1470 | 1694 | )); |
@@ -1487,14 +1711,20 @@ discard block |
||
| 1487 | 1711 | |
| 1488 | 1712 | $cnt = 0; |
| 1489 | 1713 | |
| 1490 | - foreach((array)$sortResult as $uid) { |
|
| 1714 | + foreach((array)$sortResult as $uid) |
|
| 1715 | + { |
|
| 1491 | 1716 | $sortOrder[$uid] = $cnt++; |
| 1492 | 1717 | } |
| 1493 | 1718 | |
| 1494 | 1719 | $count = 0; |
| 1495 | - if (is_object($headersNew)) { |
|
| 1496 | - if (self::$debug||self::$debugTimes) $starttime = microtime(true); |
|
| 1497 | - foreach($headersNew->ids() as $id) { |
|
| 1720 | + if (is_object($headersNew)) |
|
| 1721 | + { |
|
| 1722 | + if (self::$debug||self::$debugTimes) |
|
| 1723 | + { |
|
| 1724 | + $starttime = microtime(true); |
|
| 1725 | + } |
|
| 1726 | + foreach($headersNew->ids() as $id) |
|
| 1727 | + { |
|
| 1498 | 1728 | $_headerObject = $headersNew->get($id); |
| 1499 | 1729 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject)); |
| 1500 | 1730 | $headerObject = array(); |
@@ -1507,7 +1737,10 @@ discard block |
||
| 1507 | 1737 | // Get already cached headers, 'fetchHeaders' is a label matchimg above |
| 1508 | 1738 | $headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(); |
| 1509 | 1739 | // Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com |
| 1510 | - if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(); |
|
| 1740 | + if (empty($headerForPrio)) |
|
| 1741 | + { |
|
| 1742 | + $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(); |
|
| 1743 | + } |
|
| 1511 | 1744 | //fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns |
| 1512 | 1745 | //nothing worthwhile (as it does for googlemail accounts, when preview is switched on |
| 1513 | 1746 | if ($_fetchPreviews) |
@@ -1518,12 +1751,16 @@ discard block |
||
| 1518 | 1751 | if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio[''])) |
| 1519 | 1752 | { |
| 1520 | 1753 | $length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL); |
| 1521 | - if ($length===false) $length = strlen($bodyPreview); |
|
| 1754 | + if ($length===false) |
|
| 1755 | + { |
|
| 1756 | + $length = strlen($bodyPreview); |
|
| 1757 | + } |
|
| 1522 | 1758 | $headerForPrio = Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray(); |
| 1523 | 1759 | } |
| 1524 | 1760 | } |
| 1525 | 1761 | $headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER); |
| 1526 | - if (self::$debug) { |
|
| 1762 | + if (self::$debug) |
|
| 1763 | + { |
|
| 1527 | 1764 | 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')); |
| 1528 | 1765 | error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio)); |
| 1529 | 1766 | } |
@@ -1533,11 +1770,16 @@ discard block |
||
| 1533 | 1770 | $total--; |
| 1534 | 1771 | continue; |
| 1535 | 1772 | } |
| 1536 | - if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) { |
|
| 1773 | + if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) |
|
| 1774 | + { |
|
| 1537 | 1775 | $headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO'])); |
| 1538 | - } else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) { |
|
| 1776 | + } |
|
| 1777 | + else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) |
|
| 1778 | + { |
|
| 1539 | 1779 | $headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO'])); |
| 1540 | - } else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) { |
|
| 1780 | + } |
|
| 1781 | + else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) |
|
| 1782 | + { |
|
| 1541 | 1783 | $headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO'])); |
| 1542 | 1784 | } /*else $sent_not = "";*/ |
| 1543 | 1785 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject)); |
@@ -1569,7 +1811,11 @@ discard block |
||
| 1569 | 1811 | $rfcAddr = self::parseAddressList($ad); // does some fixing of known problems too |
| 1570 | 1812 | foreach ($rfcAddr as $_rfcAddr) |
| 1571 | 1813 | { |
| 1572 | - if (!$_rfcAddr->valid) continue; // skip. not a valid address |
|
| 1814 | + if (!$_rfcAddr->valid) |
|
| 1815 | + { |
|
| 1816 | + continue; |
|
| 1817 | + } |
|
| 1818 | + // skip. not a valid address |
|
| 1573 | 1819 | $address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal); |
| 1574 | 1820 | } |
| 1575 | 1821 | } |
@@ -1585,7 +1831,10 @@ discard block |
||
| 1585 | 1831 | { |
| 1586 | 1832 | // $bodyPreview is populated at the beginning of the loop, as it may be |
| 1587 | 1833 | // needed to parse the Headers of the Message |
| 1588 | - if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg(); |
|
| 1834 | + if (empty($bodyPreview)) |
|
| 1835 | + { |
|
| 1836 | + $bodyPreview = $_headerObject->getFullMsg(); |
|
| 1837 | + } |
|
| 1589 | 1838 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview)); |
| 1590 | 1839 | $base = Horde_Mime_Part::parseMessage($bodyPreview); |
| 1591 | 1840 | foreach($base->partIterator() as $part) |
@@ -1598,7 +1847,8 @@ discard block |
||
| 1598 | 1847 | 'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset |
| 1599 | 1848 | )), $charset, 'utf-8'); |
| 1600 | 1849 | $headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews)))); |
| 1601 | - } elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart') |
|
| 1850 | + } |
|
| 1851 | + elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart') |
|
| 1602 | 1852 | { |
| 1603 | 1853 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($part)); |
| 1604 | 1854 | } |
@@ -1614,7 +1864,10 @@ discard block |
||
| 1614 | 1864 | $messageMimeType=''; |
| 1615 | 1865 | foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type) |
| 1616 | 1866 | { |
| 1617 | - if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type; |
|
| 1867 | + if ($mime_id==0 || $messageMimeType==='') |
|
| 1868 | + { |
|
| 1869 | + $messageMimeType = $mime_type; |
|
| 1870 | + } |
|
| 1618 | 1871 | $part = $mailStructureObject->getPart($mime_id); |
| 1619 | 1872 | $partdisposition = $part->getDisposition(); |
| 1620 | 1873 | $partPrimaryType = $part->getPrimaryType(); |
@@ -1624,7 +1877,8 @@ discard block |
||
| 1624 | 1877 | // bodypreview could be found (multipart/....) |
| 1625 | 1878 | if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') && |
| 1626 | 1879 | ((intval($mime_id) === 1) || !$mime_id) && |
| 1627 | - ($partdisposition !== 'attachment')) { |
|
| 1880 | + ($partdisposition !== 'attachment')) |
|
| 1881 | + { |
|
| 1628 | 1882 | $_structure=$part; |
| 1629 | 1883 | $this->fetchPartContents($uid, $_structure, false,true); |
| 1630 | 1884 | $headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews)))); |
@@ -1646,10 +1900,19 @@ discard block |
||
| 1646 | 1900 | if ($mime_type=='message/rfc822') |
| 1647 | 1901 | { |
| 1648 | 1902 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap())); |
| 1649 | - foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;} |
|
| 1903 | + foreach($part->contentTypeMap() as $sub_id => $sub_type) |
|
| 1904 | + { |
|
| 1905 | +if ($sub_id != $mime_id) |
|
| 1906 | + { |
|
| 1907 | + $skipParts[$sub_id] = $sub_type; |
|
| 1908 | + } |
|
| 1909 | + } |
|
| 1650 | 1910 | } |
| 1651 | 1911 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts)); |
| 1652 | - if (array_key_exists($mime_id,$skipParts)) continue; |
|
| 1912 | + if (array_key_exists($mime_id,$skipParts)) |
|
| 1913 | + { |
|
| 1914 | + continue; |
|
| 1915 | + } |
|
| 1653 | 1916 | if ($partdisposition=='attachment' || |
| 1654 | 1917 | ($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs |
| 1655 | 1918 | ($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) || |
@@ -1660,7 +1923,10 @@ discard block |
||
| 1660 | 1923 | $headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid; |
| 1661 | 1924 | $headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid; |
| 1662 | 1925 | $headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id; |
| 1663 | - if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName(); |
|
| 1926 | + if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name'])) |
|
| 1927 | + { |
|
| 1928 | + $headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName(); |
|
| 1929 | + } |
|
| 1664 | 1930 | if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') || |
| 1665 | 1931 | $headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef') |
| 1666 | 1932 | { |
@@ -1674,18 +1940,27 @@ discard block |
||
| 1674 | 1940 | //error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (plain):'.array2string($mailStructureObject->findBody('plain'))); |
| 1675 | 1941 | //error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (html):'.array2string($mailStructureObject->findBody('html'))); |
| 1676 | 1942 | //if($count == 0) error_log(__METHOD__.array2string($headerObject)); |
| 1677 | - if (empty($headerObject['UID'])) continue; |
|
| 1943 | + if (empty($headerObject['UID'])) |
|
| 1944 | + { |
|
| 1945 | + continue; |
|
| 1946 | + } |
|
| 1678 | 1947 | //$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']); |
| 1679 | 1948 | // make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime |
| 1680 | - if(substr($headerObject['DATE'],-2) === 'UT') { |
|
| 1949 | + if(substr($headerObject['DATE'],-2) === 'UT') |
|
| 1950 | + { |
|
| 1681 | 1951 | $headerObject['DATE'] .= 'C'; |
| 1682 | 1952 | } |
| 1683 | - if(substr($headerObject['INTERNALDATE'],-2) === 'UT') { |
|
| 1953 | + if(substr($headerObject['INTERNALDATE'],-2) === 'UT') |
|
| 1954 | + { |
|
| 1684 | 1955 | $headerObject['INTERNALDATE'] .= 'C'; |
| 1685 | 1956 | } |
| 1686 | 1957 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#'); |
| 1687 | 1958 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']); |
| 1688 | - if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;} |
|
| 1959 | + if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) |
|
| 1960 | + { |
|
| 1961 | + foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a; |
|
| 1962 | + } |
|
| 1963 | + } |
|
| 1689 | 1964 | $retValue['header'][$sortOrder[$uid]]['subject'] = $this->decode_subject($headerObject['SUBJECT']); |
| 1690 | 1965 | $retValue['header'][$sortOrder[$uid]]['size'] = $headerObject['SIZE']; |
| 1691 | 1966 | $retValue['header'][$sortOrder[$uid]]['date'] = self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true); |
@@ -1696,25 +1971,35 @@ discard block |
||
| 1696 | 1971 | $retValue['header'][$sortOrder[$uid]]['bodypreview'] = $headerObject['BODYPREVIEW']; |
| 1697 | 1972 | $retValue['header'][$sortOrder[$uid]]['priority'] = ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3); |
| 1698 | 1973 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]])); |
| 1699 | - if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO']; |
|
| 1700 | - if (is_array($headerObject['FLAGS'])) { |
|
| 1974 | + if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) |
|
| 1975 | + { |
|
| 1976 | + $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO']; |
|
| 1977 | + } |
|
| 1978 | + if (is_array($headerObject['FLAGS'])) |
|
| 1979 | + { |
|
| 1701 | 1980 | $retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject)); |
| 1702 | 1981 | } |
| 1703 | 1982 | //error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from'))); |
| 1704 | - if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) { |
|
| 1983 | + if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) |
|
| 1984 | + { |
|
| 1705 | 1985 | $retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true); |
| 1706 | 1986 | } |
| 1707 | - if(is_array($headerObject['REPLY-TO']) && $headerObject['REPLY-TO'][0]) { |
|
| 1987 | + if(is_array($headerObject['REPLY-TO']) && $headerObject['REPLY-TO'][0]) |
|
| 1988 | + { |
|
| 1708 | 1989 | $retValue['header'][$sortOrder[$uid]]['reply_to_address'] = self::decode_header($headerObject['REPLY-TO'][0],true); |
| 1709 | 1990 | } |
| 1710 | - if(is_array($headerObject['TO']) && $headerObject['TO'][0]) { |
|
| 1991 | + if(is_array($headerObject['TO']) && $headerObject['TO'][0]) |
|
| 1992 | + { |
|
| 1711 | 1993 | $retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true); |
| 1712 | 1994 | if (count($headerObject['TO'])>1) |
| 1713 | 1995 | { |
| 1714 | 1996 | $ki=0; |
| 1715 | 1997 | foreach($headerObject['TO'] as $k => $add) |
| 1716 | 1998 | { |
| 1717 | - if ($k==0) continue; |
|
| 1999 | + if ($k==0) |
|
| 2000 | + { |
|
| 2001 | + continue; |
|
| 2002 | + } |
|
| 1718 | 2003 | //error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add)); |
| 1719 | 2004 | $retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true); |
| 1720 | 2005 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki])); |
@@ -1722,7 +2007,8 @@ discard block |
||
| 1722 | 2007 | } |
| 1723 | 2008 | } |
| 1724 | 2009 | } |
| 1725 | - if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) { |
|
| 2010 | + if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) |
|
| 2011 | + { |
|
| 1726 | 2012 | $ki=0; |
| 1727 | 2013 | foreach($headerObject['CC'] as $k => $add) |
| 1728 | 2014 | { |
@@ -1736,27 +2022,41 @@ discard block |
||
| 1736 | 2022 | |
| 1737 | 2023 | $count++; |
| 1738 | 2024 | } |
| 1739 | - if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') '); |
|
| 2025 | + if (self::$debug||self::$debugTimes) |
|
| 2026 | + { |
|
| 2027 | + self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') '); |
|
| 2028 | + } |
|
| 1740 | 2029 | //self::$debug=false; |
| 1741 | 2030 | // sort the messages to the requested displayorder |
| 1742 | - if(is_array($retValue['header'])) { |
|
| 2031 | + if(is_array($retValue['header'])) |
|
| 2032 | + { |
|
| 1743 | 2033 | $countMessages = $total; |
| 1744 | - if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages']; |
|
| 2034 | + if (isset($_filter['range'])) |
|
| 2035 | + { |
|
| 2036 | + $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages']; |
|
| 2037 | + } |
|
| 1745 | 2038 | ksort($retValue['header']); |
| 1746 | 2039 | $retValue['info']['total'] = $total; |
| 1747 | 2040 | //if ($_startMessage>$total) $_startMessage = $total-($count-1); |
| 1748 | 2041 | $retValue['info']['first'] = $_startMessage; |
| 1749 | 2042 | $retValue['info']['last'] = $_startMessage + $count - 1 ; |
| 1750 | 2043 | return $retValue; |
| 1751 | - } else { |
|
| 2044 | + } |
|
| 2045 | + else |
|
| 2046 | + { |
|
| 1752 | 2047 | $retValue = array(); |
| 1753 | 2048 | $retValue['info']['total'] = 0; |
| 1754 | 2049 | $retValue['info']['first'] = 0; |
| 1755 | 2050 | $retValue['info']['last'] = 0; |
| 1756 | 2051 | return $retValue; |
| 1757 | 2052 | } |
| 1758 | - } else { |
|
| 1759 | - if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE)); |
|
| 2053 | + } |
|
| 2054 | + else |
|
| 2055 | + { |
|
| 2056 | + if ($headersNew == null && empty($_thisUIDOnly)) |
|
| 2057 | + { |
|
| 2058 | + error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE)); |
|
| 2059 | + } |
|
| 1760 | 2060 | $retValue = array(); |
| 1761 | 2061 | $retValue['info']['total'] = 0; |
| 1762 | 2062 | $retValue['info']['first'] = 0; |
@@ -1773,7 +2073,10 @@ discard block |
||
| 1773 | 2073 | */ |
| 1774 | 2074 | static function prepareFlagsArray($headerObject) |
| 1775 | 2075 | { |
| 1776 | - if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']); |
|
| 2076 | + if (is_array($headerObject['FLAGS'])) |
|
| 2077 | + { |
|
| 2078 | + $headerFlags = array_map('strtolower',$headerObject['FLAGS']); |
|
| 2079 | + } |
|
| 1777 | 2080 | $retValue = array(); |
| 1778 | 2081 | $retValue['recent'] = in_array('\\recent', $headerFlags); |
| 1779 | 2082 | $retValue['flagged'] = in_array('\\flagged', $headerFlags); |
@@ -1824,26 +2127,45 @@ discard block |
||
| 1824 | 2127 | //error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter)); |
| 1825 | 2128 | $try2useCache = true; |
| 1826 | 2129 | static $eMailListContainsDeletedMessages = null; |
| 1827 | - if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 2130 | + if (is_null($eMailListContainsDeletedMessages)) |
|
| 2131 | + { |
|
| 2132 | + $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 2133 | + } |
|
| 1828 | 2134 | // this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED |
| 1829 | 2135 | if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false))) |
| 1830 | 2136 | { |
| 1831 | - if (self::$debugTimes) $starttime = microtime(true); |
|
| 1832 | - 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); |
|
| 2137 | + if (self::$debugTimes) |
|
| 2138 | + { |
|
| 2139 | + $starttime = microtime(true); |
|
| 2140 | + } |
|
| 2141 | + if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) |
|
| 2142 | + { |
|
| 2143 | + $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 2144 | + } |
|
| 1833 | 2145 | $five=true; |
| 1834 | 2146 | $dReverse=1; |
| 1835 | 2147 | $deletedMessages = $this->getSortedList($_folderName, 0, $dReverse, array('status'=>array('DELETED')),$five,false); |
| 1836 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages)); |
|
| 1837 | - $eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count']; |
|
| 1838 | - Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1); |
|
| 1839 | - 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']); |
|
| 2148 | + if (self::$debug) |
|
| 2149 | + { |
|
| 2150 | + error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages)); |
|
| 2151 | + } |
|
| 2152 | + $eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count']; |
|
| 2153 | + Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1); |
|
| 2154 | + if (self::$debugTimes) |
|
| 2155 | + { |
|
| 2156 | + self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') '); |
|
| 2157 | + } |
|
| 2158 | + //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']); |
|
| 1840 | 2159 | } |
| 1841 | 2160 | $try2useCache = false; |
| 1842 | 2161 | //self::$supportsORinQuery[$this->profileID]=true; |
| 1843 | 2162 | if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID])) |
| 1844 | 2163 | { |
| 1845 | 2164 | self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10); |
| 1846 | - if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true; |
|
| 2165 | + if (!isset(self::$supportsORinQuery[$this->profileID])) |
|
| 2166 | + { |
|
| 2167 | + self::$supportsORinQuery[$this->profileID]=true; |
|
| 2168 | + } |
|
| 1847 | 2169 | } |
| 1848 | 2170 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]); |
| 1849 | 2171 | $filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]); |
@@ -1854,15 +2176,26 @@ discard block |
||
| 1854 | 2176 | } |
| 1855 | 2177 | //_debug_array($filter); |
| 1856 | 2178 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability())); |
| 1857 | - if($this->icServer->hasCapability('SORT')) { |
|
| 2179 | + if($this->icServer->hasCapability('SORT')) |
|
| 2180 | + { |
|
| 1858 | 2181 | // when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client |
| 1859 | 2182 | // thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if |
| 1860 | 2183 | // there is no messing with the dates) |
| 1861 | 2184 | //if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE'; |
| 1862 | - if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse"); |
|
| 2185 | + if (self::$debug) |
|
| 2186 | + { |
|
| 2187 | + error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse"); |
|
| 2188 | + } |
|
| 1863 | 2189 | $sortOrder = $this->_getSortString($_sort, $_reverse); |
| 1864 | - if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already |
|
| 1865 | - if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter)); |
|
| 2190 | + if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) |
|
| 2191 | + { |
|
| 2192 | + $_reverse=false; |
|
| 2193 | + } |
|
| 2194 | + // as we reversed the result already |
|
| 2195 | + if (self::$debug) |
|
| 2196 | + { |
|
| 2197 | + error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter)); |
|
| 2198 | + } |
|
| 1866 | 2199 | try |
| 1867 | 2200 | { |
| 1868 | 2201 | $sortResult = $this->icServer->search($_folderName, $filter, array( |
@@ -1874,7 +2207,10 @@ discard block |
||
| 1874 | 2207 | //error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage()); |
| 1875 | 2208 | $resultByUid = false; |
| 1876 | 2209 | $sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE); |
| 1877 | - if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE); |
|
| 2210 | + if ($_reverse) |
|
| 2211 | + { |
|
| 2212 | + array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE); |
|
| 2213 | + } |
|
| 1878 | 2214 | try |
| 1879 | 2215 | { |
| 1880 | 2216 | $sortResult = $this->icServer->search($_folderName, $filter, array( |
@@ -1886,9 +2222,17 @@ discard block |
||
| 1886 | 2222 | $sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult']; |
| 1887 | 2223 | } |
| 1888 | 2224 | } |
| 1889 | - if (self::$debug) error_log(__METHOD__.print_r($sortResult,true)); |
|
| 1890 | - } else { |
|
| 1891 | - if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability"); |
|
| 2225 | + if (self::$debug) |
|
| 2226 | + { |
|
| 2227 | + error_log(__METHOD__.print_r($sortResult,true)); |
|
| 2228 | + } |
|
| 2229 | + } |
|
| 2230 | + else |
|
| 2231 | + { |
|
| 2232 | + if (self::$debug) |
|
| 2233 | + { |
|
| 2234 | + error_log(__METHOD__." Mailserver has NO SORT Capability"); |
|
| 2235 | + } |
|
| 1892 | 2236 | //$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE); |
| 1893 | 2237 | //if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE); |
| 1894 | 2238 | try |
@@ -1902,7 +2246,10 @@ discard block |
||
| 1902 | 2246 | // possible error OR Query. But Horde gives no detailed Info :-( |
| 1903 | 2247 | self::$supportsORinQuery[$this->profileID]=false; |
| 1904 | 2248 | Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10); |
| 1905 | - if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message); |
|
| 2249 | + if (self::$debug) |
|
| 2250 | + { |
|
| 2251 | + error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message); |
|
| 2252 | + } |
|
| 1906 | 2253 | $filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]); |
| 1907 | 2254 | try |
| 1908 | 2255 | { |
@@ -1913,11 +2260,15 @@ discard block |
||
| 1913 | 2260 | { |
| 1914 | 2261 | } |
| 1915 | 2262 | } |
| 1916 | - if(is_array($sortResult['match'])) { |
|
| 2263 | + if(is_array($sortResult['match'])) |
|
| 2264 | + { |
|
| 1917 | 2265 | // not sure that this is going so succeed as $sortResult['match'] is a hordeObject |
| 1918 | 2266 | sort($sortResult['match'], SORT_NUMERIC); |
| 1919 | 2267 | } |
| 1920 | - if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true)); |
|
| 2268 | + if (self::$debug) |
|
| 2269 | + { |
|
| 2270 | + error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true)); |
|
| 2271 | + } |
|
| 1921 | 2272 | } |
| 1922 | 2273 | if ($setSession) |
| 1923 | 2274 | { |
@@ -1946,7 +2297,8 @@ discard block |
||
| 1946 | 2297 | $_reverse=false; |
| 1947 | 2298 | if (is_numeric($_sort)) |
| 1948 | 2299 | { |
| 1949 | - switch($_sort) { |
|
| 2300 | + switch($_sort) |
|
| 2301 | + { |
|
| 1950 | 2302 | case 2: |
| 1951 | 2303 | $retValue = array(Horde_Imap_Client::SORT_FROM); |
| 1952 | 2304 | break; |
@@ -1968,7 +2320,8 @@ discard block |
||
| 1968 | 2320 | } |
| 1969 | 2321 | else |
| 1970 | 2322 | { |
| 1971 | - switch(strtoupper($_sort)) { |
|
| 2323 | + switch(strtoupper($_sort)) |
|
| 2324 | + { |
|
| 1972 | 2325 | case 'FROMADDRESS': |
| 1973 | 2326 | $retValue = array(Horde_Imap_Client::SORT_FROM); |
| 1974 | 2327 | break; |
@@ -1994,7 +2347,10 @@ discard block |
||
| 1994 | 2347 | break; |
| 1995 | 2348 | } |
| 1996 | 2349 | } |
| 1997 | - if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE); |
|
| 2350 | + if ($_reverse) |
|
| 2351 | + { |
|
| 2352 | + array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE); |
|
| 2353 | + } |
|
| 1998 | 2354 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue); |
| 1999 | 2355 | return $retValue; |
| 2000 | 2356 | } |
@@ -2013,7 +2369,10 @@ discard block |
||
| 2013 | 2369 | $imapFilter->charset('UTF-8'); |
| 2014 | 2370 | |
| 2015 | 2371 | //_debug_array($_criterias); |
| 2016 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias))); |
|
| 2372 | + if (self::$debug) |
|
| 2373 | + { |
|
| 2374 | + error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias))); |
|
| 2375 | + } |
|
| 2017 | 2376 | if((!is_array($_criterias) || $_criterias['status']=='any') && |
| 2018 | 2377 | (!isset($_criterias['string']) || empty($_criterias['string'])) && |
| 2019 | 2378 | (!isset($_criterias['range'])|| empty($_criterias['range']) || |
@@ -2028,11 +2387,13 @@ discard block |
||
| 2028 | 2387 | // statusQuery MUST be placed first, as search for subject/mailbody and such is |
| 2029 | 2388 | // depending on charset. flagSearch is not BUT messes the charset if called afterwards |
| 2030 | 2389 | $statusQueryValid = false; |
| 2031 | - foreach((array)$_criterias['status'] as $k => $criteria) { |
|
| 2390 | + foreach((array)$_criterias['status'] as $k => $criteria) |
|
| 2391 | + { |
|
| 2032 | 2392 | $imapStatusFilter = new Horde_Imap_Client_Search_Query(); |
| 2033 | 2393 | $imapStatusFilter->charset('UTF-8'); |
| 2034 | 2394 | $criteria = strtoupper($criteria); |
| 2035 | - switch ($criteria) { |
|
| 2395 | + switch ($criteria) |
|
| 2396 | + { |
|
| 2036 | 2397 | case 'ANSWERED': |
| 2037 | 2398 | case 'DELETED': |
| 2038 | 2399 | case 'FLAGGED': |
@@ -2115,9 +2476,11 @@ discard block |
||
| 2115 | 2476 | $imapSearchFilter = new Horde_Imap_Client_Search_Query(); |
| 2116 | 2477 | $imapSearchFilter->charset('UTF-8'); |
| 2117 | 2478 | |
| 2118 | - if(!empty($_criterias['string'])) { |
|
| 2479 | + if(!empty($_criterias['string'])) |
|
| 2480 | + { |
|
| 2119 | 2481 | $criteria = strtoupper($_criterias['type']); |
| 2120 | - switch ($criteria) { |
|
| 2482 | + switch ($criteria) |
|
| 2483 | + { |
|
| 2121 | 2484 | case 'BYDATE': |
| 2122 | 2485 | case 'QUICK': |
| 2123 | 2486 | case 'QUICKWITHCC': |
@@ -2125,9 +2488,12 @@ discard block |
||
| 2125 | 2488 | //$imapSearchFilter->charset('UTF-8'); |
| 2126 | 2489 | $imapFilter2 = new Horde_Imap_Client_Search_Query(); |
| 2127 | 2490 | $imapFilter2->charset('UTF-8'); |
| 2128 | - if($this->isSentFolder($_folder)) { |
|
| 2491 | + if($this->isSentFolder($_folder)) |
|
| 2492 | + { |
|
| 2129 | 2493 | $imapFilter2->headerText('TO', $_criterias['string'], $not=false); |
| 2130 | - } else { |
|
| 2494 | + } |
|
| 2495 | + else |
|
| 2496 | + { |
|
| 2131 | 2497 | $imapFilter2->headerText('FROM', $_criterias['string'], $not=false); |
| 2132 | 2498 | } |
| 2133 | 2499 | if ($_supportsOrInQuery) |
@@ -2158,7 +2524,10 @@ discard block |
||
| 2158 | 2524 | 'GB'=>1024*1000*1000,'G'=>1024*1000*1000, |
| 2159 | 2525 | 'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000); |
| 2160 | 2526 | $numberinBytes=(float)$_criterias['string']; |
| 2161 | - if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit]; |
|
| 2527 | + if (isset($multipleBy[$unit])) |
|
| 2528 | + { |
|
| 2529 | + $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit]; |
|
| 2530 | + } |
|
| 2162 | 2531 | //error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes); |
| 2163 | 2532 | $_criterias['string']=$numberinBytes; |
| 2164 | 2533 | } |
@@ -2195,8 +2564,14 @@ discard block |
||
| 2195 | 2564 | break; |
| 2196 | 2565 | } |
| 2197 | 2566 | } |
| 2198 | - if ($statusQueryValid && !$queryValid) $queryValid=true; |
|
| 2199 | - if ($queryValid) $imapFilter->andSearch($imapSearchFilter); |
|
| 2567 | + if ($statusQueryValid && !$queryValid) |
|
| 2568 | + { |
|
| 2569 | + $queryValid=true; |
|
| 2570 | + } |
|
| 2571 | + if ($queryValid) |
|
| 2572 | + { |
|
| 2573 | + $imapFilter->andSearch($imapSearchFilter); |
|
| 2574 | + } |
|
| 2200 | 2575 | |
| 2201 | 2576 | if (isset($_criterias['range']) && !empty($_criterias['range'])) |
| 2202 | 2577 | { |
@@ -2211,7 +2586,8 @@ discard block |
||
| 2211 | 2586 | unset($_criterias['before']); |
| 2212 | 2587 | $criteria=$_criterias['range']='ON'; |
| 2213 | 2588 | } |
| 2214 | - switch ($criteria) { |
|
| 2589 | + switch ($criteria) |
|
| 2590 | + { |
|
| 2215 | 2591 | case 'BETWEEN': |
| 2216 | 2592 | //try to be smart about missing |
| 2217 | 2593 | //enddate |
@@ -2247,8 +2623,14 @@ discard block |
||
| 2247 | 2623 | $rangeValid = true; |
| 2248 | 2624 | break; |
| 2249 | 2625 | } |
| 2250 | - if ($rangeValid && !$queryValid) $queryValid=true; |
|
| 2251 | - if ($rangeValid) $imapFilter->andSearch($imapRangeFilter); |
|
| 2626 | + if ($rangeValid && !$queryValid) |
|
| 2627 | + { |
|
| 2628 | + $queryValid=true; |
|
| 2629 | + } |
|
| 2630 | + if ($rangeValid) |
|
| 2631 | + { |
|
| 2632 | + $imapFilter->andSearch($imapRangeFilter); |
|
| 2633 | + } |
|
| 2252 | 2634 | } |
| 2253 | 2635 | if (self::$debug) |
| 2254 | 2636 | { |
@@ -2256,10 +2638,13 @@ discard block |
||
| 2256 | 2638 | $query_str = $imapFilter->build(); |
| 2257 | 2639 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias))); |
| 2258 | 2640 | } |
| 2259 | - if($queryValid==false) { |
|
| 2641 | + if($queryValid==false) |
|
| 2642 | + { |
|
| 2260 | 2643 | $imapFilter->flag('DELETED', $set=false); |
| 2261 | 2644 | return $imapFilter; |
| 2262 | - } else { |
|
| 2645 | + } |
|
| 2646 | + else |
|
| 2647 | + { |
|
| 2263 | 2648 | return $imapFilter; |
| 2264 | 2649 | } |
| 2265 | 2650 | } |
@@ -2316,7 +2701,10 @@ discard block |
||
| 2316 | 2701 | } |
| 2317 | 2702 | $stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal); |
| 2318 | 2703 | } |
| 2319 | - if (!empty($stringA)) $_string = implode(',',$stringA); |
|
| 2704 | + if (!empty($stringA)) |
|
| 2705 | + { |
|
| 2706 | + $_string = implode(',',$stringA); |
|
| 2707 | + } |
|
| 2320 | 2708 | } |
| 2321 | 2709 | if ($_tryIDNConversion==='FORCE') |
| 2322 | 2710 | { |
@@ -2341,7 +2729,10 @@ discard block |
||
| 2341 | 2729 | { |
| 2342 | 2730 | return 'No Subject'; |
| 2343 | 2731 | } |
| 2344 | - if ($decode) $_string = self::decode_header($_string); |
|
| 2732 | + if ($decode) |
|
| 2733 | + { |
|
| 2734 | + $_string = self::decode_header($_string); |
|
| 2735 | + } |
|
| 2345 | 2736 | // make sure its utf-8 |
| 2346 | 2737 | $test = @json_encode($_string); |
| 2347 | 2738 | if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0) |
@@ -2379,7 +2770,8 @@ discard block |
||
| 2379 | 2770 | * @param string _parent the parent foldername |
| 2380 | 2771 | * @return ISO-8859-1 / UTF7-IMAP encoded string |
| 2381 | 2772 | */ |
| 2382 | - function _encodeFolderName($_folderName) { |
|
| 2773 | + function _encodeFolderName($_folderName) |
|
| 2774 | + { |
|
| 2383 | 2775 | return Translation::convert($_folderName, self::$displayCharset, 'ISO-8859-1'); |
| 2384 | 2776 | #return Translation::convert($_folderName, self::$displayCharset, 'UTF7-IMAP'); |
| 2385 | 2777 | } |
@@ -2395,21 +2787,36 @@ discard block |
||
| 2395 | 2787 | */ |
| 2396 | 2788 | function createFolder($_parent, $_folderName, &$_error) |
| 2397 | 2789 | { |
| 2398 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace()); |
|
| 2790 | + if (self::$debug) |
|
| 2791 | + { |
|
| 2792 | + error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace()); |
|
| 2793 | + } |
|
| 2399 | 2794 | $parent = $_parent;//$this->_encodeFolderName($_parent); |
| 2400 | 2795 | $folderName = $_folderName;//$this->_encodeFolderName($_folderName); |
| 2401 | 2796 | |
| 2402 | - if(empty($parent)) { |
|
| 2797 | + if(empty($parent)) |
|
| 2798 | + { |
|
| 2403 | 2799 | $newFolderName = $folderName; |
| 2404 | - } else { |
|
| 2800 | + } |
|
| 2801 | + else |
|
| 2802 | + { |
|
| 2405 | 2803 | $HierarchyDelimiter = $this->getHierarchyDelimiter(); |
| 2406 | 2804 | $newFolderName = $parent . $HierarchyDelimiter . $folderName; |
| 2407 | 2805 | } |
| 2408 | - if (empty($newFolderName)) return false; |
|
| 2409 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName); |
|
| 2806 | + if (empty($newFolderName)) |
|
| 2807 | + { |
|
| 2808 | + return false; |
|
| 2809 | + } |
|
| 2810 | + if (self::$debug) |
|
| 2811 | + { |
|
| 2812 | + error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName); |
|
| 2813 | + } |
|
| 2410 | 2814 | if ($this->folderExists($newFolderName,true)) |
| 2411 | 2815 | { |
| 2412 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists."); |
|
| 2816 | + if (self::$debug) |
|
| 2817 | + { |
|
| 2818 | + error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists."); |
|
| 2819 | + } |
|
| 2413 | 2820 | return $newFolderName; |
| 2414 | 2821 | } |
| 2415 | 2822 | try |
@@ -2457,13 +2864,19 @@ discard block |
||
| 2457 | 2864 | $parent = $_parent;//$this->_encodeFolderName($_parent); |
| 2458 | 2865 | $folderName = $_folderName;//$this->_encodeFolderName($_folderName); |
| 2459 | 2866 | |
| 2460 | - if(empty($parent)) { |
|
| 2867 | + if(empty($parent)) |
|
| 2868 | + { |
|
| 2461 | 2869 | $newFolderName = $folderName; |
| 2462 | - } else { |
|
| 2870 | + } |
|
| 2871 | + else |
|
| 2872 | + { |
|
| 2463 | 2873 | $HierarchyDelimiter = $this->getHierarchyDelimiter(); |
| 2464 | 2874 | $newFolderName = $parent . $HierarchyDelimiter . $folderName; |
| 2465 | 2875 | } |
| 2466 | - if (self::$debug) error_log("create folder: $newFolderName"); |
|
| 2876 | + if (self::$debug) |
|
| 2877 | + { |
|
| 2878 | + error_log("create folder: $newFolderName"); |
|
| 2879 | + } |
|
| 2467 | 2880 | try |
| 2468 | 2881 | { |
| 2469 | 2882 | $this->icServer->renameMailbox($oldFolderName, $newFolderName); |
@@ -2537,8 +2950,14 @@ discard block |
||
| 2537 | 2950 | */ |
| 2538 | 2951 | function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true) |
| 2539 | 2952 | { |
| 2540 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible"); |
|
| 2541 | - if (self::$debugTimes) $starttime = microtime (true); |
|
| 2953 | + if (self::$debug) |
|
| 2954 | + { |
|
| 2955 | + error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible"); |
|
| 2956 | + } |
|
| 2957 | + if (self::$debugTimes) |
|
| 2958 | + { |
|
| 2959 | + $starttime = microtime (true); |
|
| 2960 | + } |
|
| 2542 | 2961 | static $folders2return; |
| 2543 | 2962 | //$_subscribedOnly=false; |
| 2544 | 2963 | // always use static on single request if info is available; |
@@ -2546,23 +2965,35 @@ discard block |
||
| 2546 | 2965 | // set $_useCacheIfPossible to false ! |
| 2547 | 2966 | if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId])) |
| 2548 | 2967 | { |
| 2549 | - if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') '); |
|
| 2968 | + if (self::$debugTimes) |
|
| 2969 | + { |
|
| 2970 | + self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') '); |
|
| 2971 | + } |
|
| 2550 | 2972 | return $folders2return[$this->icServer->ImapServerId]; |
| 2551 | 2973 | } |
| 2552 | 2974 | |
| 2553 | 2975 | if ($_subscribedOnly && $_getCounters===false) |
| 2554 | 2976 | { |
| 2555 | - if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 2977 | + if (is_null($folders2return)) |
|
| 2978 | + { |
|
| 2979 | + $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 2980 | + } |
|
| 2556 | 2981 | if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId])) |
| 2557 | 2982 | { |
| 2558 | 2983 | //error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId])); |
| 2559 | - if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') '); |
|
| 2984 | + if (self::$debugTimes) |
|
| 2985 | + { |
|
| 2986 | + self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') '); |
|
| 2987 | + } |
|
| 2560 | 2988 | return $folders2return[$this->icServer->ImapServerId]; |
| 2561 | 2989 | } |
| 2562 | 2990 | } |
| 2563 | 2991 | // use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId] |
| 2564 | 2992 | static $folderBasicInfo; |
| 2565 | - 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); |
|
| 2993 | + if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId])) |
|
| 2994 | + { |
|
| 2995 | + $folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 2996 | + } |
|
| 2566 | 2997 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId]))); |
| 2567 | 2998 | |
| 2568 | 2999 | $delimiter = $this->getHierarchyDelimiter(); |
@@ -2575,7 +3006,8 @@ discard block |
||
| 2575 | 3006 | $inboxData->shortFolderName = 'INBOX'; |
| 2576 | 3007 | $inboxData->shortDisplayName = lang('INBOX'); |
| 2577 | 3008 | $inboxData->subscribed = true; |
| 2578 | - if($_getCounters == true) { |
|
| 3009 | + if($_getCounters == true) |
|
| 3010 | + { |
|
| 2579 | 3011 | $inboxData->counter = $this->getMailBoxCounters('INBOX'); |
| 2580 | 3012 | } |
| 2581 | 3013 | // force unsubscribed by preference showAllFoldersInFolderPane |
@@ -2594,12 +3026,14 @@ discard block |
||
| 2594 | 3026 | //error_log(__METHOD__.__LINE__.array2string($nameSpace)); |
| 2595 | 3027 | if (is_array($nameSpace)) |
| 2596 | 3028 | { |
| 2597 | - foreach($nameSpace as $k => $singleNameSpace) { |
|
| 3029 | + foreach($nameSpace as $k => $singleNameSpace) |
|
| 3030 | + { |
|
| 2598 | 3031 | $type = $singleNameSpace['type']; |
| 2599 | 3032 | // the following line (assumption that for the same namespace the delimiter should be equal) may be wrong |
| 2600 | 3033 | $foldersNameSpace[$type]['delimiter'] = $singleNameSpace['delimiter']; |
| 2601 | 3034 | |
| 2602 | - if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) { |
|
| 3035 | + if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) |
|
| 3036 | + { |
|
| 2603 | 3037 | // fetch and sort the subscribed folders |
| 2604 | 3038 | // we alway fetch the subscribed, as this provides the only way to tell |
| 2605 | 3039 | // if a folder is subscribed or not |
@@ -2650,8 +3084,12 @@ discard block |
||
| 2650 | 3084 | } |
| 2651 | 3085 | } |
| 2652 | 3086 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($foldersNameSpace[$type]['subscribed'])); |
| 2653 | - if (!is_array($foldersNameSpace[$type]['all'])) $foldersNameSpace[$type]['all'] = array(); |
|
| 2654 | - if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) { |
|
| 3087 | + if (!is_array($foldersNameSpace[$type]['all'])) |
|
| 3088 | + { |
|
| 3089 | + $foldersNameSpace[$type]['all'] = array(); |
|
| 3090 | + } |
|
| 3091 | + if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) |
|
| 3092 | + { |
|
| 2655 | 3093 | continue; |
| 2656 | 3094 | } |
| 2657 | 3095 | |
@@ -2681,7 +3119,8 @@ discard block |
||
| 2681 | 3119 | } |
| 2682 | 3120 | |
| 2683 | 3121 | //error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($allMailboxesExt)); |
| 2684 | - foreach ($allMailboxesExt as $mbx) { |
|
| 3122 | + foreach ($allMailboxesExt as $mbx) |
|
| 3123 | + { |
|
| 2685 | 3124 | if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']])) |
| 2686 | 3125 | { |
| 2687 | 3126 | $folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array( |
@@ -2704,20 +3143,33 @@ discard block |
||
| 2704 | 3143 | if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])|| |
| 2705 | 3144 | isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])|| |
| 2706 | 3145 | (substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)])) |
| 2707 | - ) continue; |
|
| 3146 | + ) |
|
| 3147 | + { |
|
| 3148 | + continue; |
|
| 3149 | + } |
|
| 2708 | 3150 | |
| 2709 | 3151 | //echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>"; |
| 2710 | 3152 | $allMailBoxesExtSorted[$mbx['MAILBOX']] = $mbx; |
| 2711 | 3153 | } |
| 2712 | - if (is_array($allMailBoxesExtSorted)) ksort($allMailBoxesExtSorted); |
|
| 3154 | + if (is_array($allMailBoxesExtSorted)) |
|
| 3155 | + { |
|
| 3156 | + ksort($allMailBoxesExtSorted); |
|
| 3157 | + } |
|
| 2713 | 3158 | //_debug_array(array_keys($allMailBoxesExtSorted)); |
| 2714 | 3159 | $allMailboxes = array(); |
| 2715 | - foreach ((array)$allMailBoxesExtSorted as $mbx) { |
|
| 2716 | - if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX']; |
|
| 3160 | + foreach ((array)$allMailBoxesExtSorted as $mbx) |
|
| 3161 | + { |
|
| 3162 | + if (!in_array($mbx['MAILBOX'],$allMailboxes)) |
|
| 3163 | + { |
|
| 3164 | + $allMailboxes[] = $mbx['MAILBOX']; |
|
| 3165 | + } |
|
| 2717 | 3166 | //echo "Result:";_debug_array($allMailboxes); |
| 2718 | 3167 | } |
| 2719 | 3168 | $foldersNameSpace[$type]['all'] = $allMailboxes; |
| 2720 | - if (is_array($foldersNameSpace[$type]['all'])) sort($foldersNameSpace[$type]['all']); |
|
| 3169 | + if (is_array($foldersNameSpace[$type]['all'])) |
|
| 3170 | + { |
|
| 3171 | + sort($foldersNameSpace[$type]['all']); |
|
| 3172 | + } |
|
| 2721 | 3173 | } |
| 2722 | 3174 | } |
| 2723 | 3175 | } |
@@ -2726,24 +3178,50 @@ discard block |
||
| 2726 | 3178 | //echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace); |
| 2727 | 3179 | $autoFolderObjects = $folders = array(); |
| 2728 | 3180 | $autofolder_exists = array(); |
| 2729 | - foreach( array('personal', 'others', 'shared') as $type) { |
|
| 2730 | - if(isset($foldersNameSpace[$type])) { |
|
| 2731 | - if($_subscribedOnly) { |
|
| 2732 | - if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed']; |
|
| 2733 | - } else { |
|
| 2734 | - if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all']; |
|
| 2735 | - } |
|
| 2736 | - foreach((array)$listOfFolders as $folderName) { |
|
| 3181 | + foreach( array('personal', 'others', 'shared') as $type) |
|
| 3182 | + { |
|
| 3183 | + if(isset($foldersNameSpace[$type])) |
|
| 3184 | + { |
|
| 3185 | + if($_subscribedOnly) |
|
| 3186 | + { |
|
| 3187 | + if( !empty($foldersNameSpace[$type]['subscribed']) ) |
|
| 3188 | + { |
|
| 3189 | + $listOfFolders = $foldersNameSpace[$type]['subscribed']; |
|
| 3190 | + } |
|
| 3191 | + } |
|
| 3192 | + else |
|
| 3193 | + { |
|
| 3194 | + if( !empty($foldersNameSpace[$type]['all'])) |
|
| 3195 | + { |
|
| 3196 | + $listOfFolders = $foldersNameSpace[$type]['all']; |
|
| 3197 | + } |
|
| 3198 | + } |
|
| 3199 | + foreach((array)$listOfFolders as $folderName) |
|
| 3200 | + { |
|
| 2737 | 3201 | //echo "<br>FolderToCheck:$folderName<br>"; |
| 2738 | 3202 | //error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName); |
| 2739 | - if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go. |
|
| 2740 | - if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) { |
|
| 3203 | + if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) |
|
| 3204 | + { |
|
| 3205 | + continue; |
|
| 3206 | + } |
|
| 3207 | + //when subscribedonly, we fetch all folders in one go. |
|
| 3208 | + if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) |
|
| 3209 | + { |
|
| 2741 | 3210 | #echo "$folderName failed to be here <br>"; |
| 2742 | 3211 | continue; |
| 2743 | 3212 | } |
| 2744 | - if (isset($folders[$folderName])) continue; |
|
| 2745 | - if (isset($autoFolderObjects[$folderName])) continue; |
|
| 2746 | - if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter']; |
|
| 3213 | + if (isset($folders[$folderName])) |
|
| 3214 | + { |
|
| 3215 | + continue; |
|
| 3216 | + } |
|
| 3217 | + if (isset($autoFolderObjects[$folderName])) |
|
| 3218 | + { |
|
| 3219 | + continue; |
|
| 3220 | + } |
|
| 3221 | + if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) |
|
| 3222 | + { |
|
| 3223 | + $delimiter = $foldersNameSpace[$type]['delimiter']; |
|
| 3224 | + } |
|
| 2747 | 3225 | $folderParts = explode($delimiter, $folderName); |
| 2748 | 3226 | $shortName = array_pop($folderParts); |
| 2749 | 3227 | |
@@ -2751,17 +3229,20 @@ discard block |
||
| 2751 | 3229 | $folderObject->delimiter = $delimiter; |
| 2752 | 3230 | $folderObject->folderName = $folderName; |
| 2753 | 3231 | $folderObject->shortFolderName = $shortName; |
| 2754 | - if(!$_subscribedOnly) { |
|
| 3232 | + if(!$_subscribedOnly) |
|
| 3233 | + { |
|
| 2755 | 3234 | #echo $folderName."->".$type."<br>"; |
| 2756 | 3235 | #_debug_array($foldersNameSpace[$type]['subscribed']); |
| 2757 | 3236 | $folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']); |
| 2758 | 3237 | } |
| 2759 | 3238 | |
| 2760 | - if($_getCounters == true) { |
|
| 3239 | + if($_getCounters == true) |
|
| 3240 | + { |
|
| 2761 | 3241 | //error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName); |
| 2762 | 3242 | $folderObject->counter = $this->getMailBoxCounters($folderName); |
| 2763 | 3243 | } |
| 2764 | - if(strtoupper($folderName) == 'INBOX') { |
|
| 3244 | + if(strtoupper($folderName) == 'INBOX') |
|
| 3245 | + { |
|
| 2765 | 3246 | $folderName = 'INBOX'; |
| 2766 | 3247 | $folderObject->folderName = 'INBOX'; |
| 2767 | 3248 | $folderObject->shortFolderName = 'INBOX'; |
@@ -2769,24 +3250,34 @@ discard block |
||
| 2769 | 3250 | $folderObject->shortDisplayName = lang('INBOX'); |
| 2770 | 3251 | $folderObject->subscribed = true; |
| 2771 | 3252 | // translate the automatic Folders (Sent, Drafts, ...) like the INBOX |
| 2772 | - } elseif (in_array($shortName,self::$autoFolders)) { |
|
| 3253 | + } |
|
| 3254 | + elseif (in_array($shortName,self::$autoFolders)) |
|
| 3255 | + { |
|
| 2773 | 3256 | $tmpfolderparts = explode($delimiter,$folderObject->folderName); |
| 2774 | 3257 | array_pop($tmpfolderparts); |
| 2775 | 3258 | $folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName); |
| 2776 | 3259 | $folderObject->shortDisplayName = lang($shortName); |
| 2777 | 3260 | unset($tmpfolderparts); |
| 2778 | - } else { |
|
| 3261 | + } |
|
| 3262 | + else |
|
| 3263 | + { |
|
| 2779 | 3264 | $folderObject->displayName = $folderObject->folderName; |
| 2780 | 3265 | $folderObject->shortDisplayName = $shortName; |
| 2781 | 3266 | } |
| 2782 | 3267 | //$folderName = $folderName; |
| 2783 | - if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) { |
|
| 3268 | + if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) |
|
| 3269 | + { |
|
| 2784 | 3270 | $autoFolderObjects[$folderName] = $folderObject; |
| 2785 | - } else { |
|
| 3271 | + } |
|
| 3272 | + else |
|
| 3273 | + { |
|
| 2786 | 3274 | $folders[$folderName] = $folderObject; |
| 2787 | 3275 | } |
| 2788 | 3276 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName); |
| 2789 | - if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); |
|
| 3277 | + if (!isset(self::$specialUseFolders)) |
|
| 3278 | + { |
|
| 3279 | + $this->getSpecialUseFolders (); |
|
| 3280 | + } |
|
| 2790 | 3281 | if (isset(self::$specialUseFolders[$folderName])) |
| 2791 | 3282 | { |
| 2792 | 3283 | $autofolder_exists[$folderName] = self::$specialUseFolders[$folderName]; |
@@ -2794,7 +3285,8 @@ discard block |
||
| 2794 | 3285 | } |
| 2795 | 3286 | } |
| 2796 | 3287 | } |
| 2797 | - if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) { |
|
| 3288 | + if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) |
|
| 3289 | + { |
|
| 2798 | 3290 | uasort($autoFolderObjects,array($this,"sortByAutoFolderPos")); |
| 2799 | 3291 | } |
| 2800 | 3292 | // check if some standard folders are missing and need to be created |
@@ -2803,7 +3295,10 @@ discard block |
||
| 2803 | 3295 | // if new folders have been created, re-read folders ignoring the cache |
| 2804 | 3296 | return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false); // false = do NOT use cache |
| 2805 | 3297 | } |
| 2806 | - if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName")); |
|
| 3298 | + if (is_array($folders)) |
|
| 3299 | + { |
|
| 3300 | + uasort($folders,array($this,"sortByDisplayName")); |
|
| 3301 | + } |
|
| 2807 | 3302 | //$folders2return = array_merge($autoFolderObjects,$folders); |
| 2808 | 3303 | //_debug_array($folders2return); #exit; |
| 2809 | 3304 | $folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders); |
@@ -2815,7 +3310,10 @@ discard block |
||
| 2815 | 3310 | Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1); |
| 2816 | 3311 | } |
| 2817 | 3312 | Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1); |
| 2818 | - if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') '); |
|
| 3313 | + if (self::$debugTimes) |
|
| 3314 | + { |
|
| 3315 | + self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') '); |
|
| 3316 | + } |
|
| 2819 | 3317 | return $folders2return[$this->icServer->ImapServerId]; |
| 2820 | 3318 | } |
| 2821 | 3319 | |
@@ -2843,31 +3341,44 @@ discard block |
||
| 2843 | 3341 | |
| 2844 | 3342 | $folders = $nameSpace = array(); |
| 2845 | 3343 | $nameSpaceTmp = $this->_getNameSpaces(); |
| 2846 | - foreach($nameSpaceTmp as $k => $singleNameSpace) { |
|
| 3344 | + foreach($nameSpaceTmp as $k => $singleNameSpace) |
|
| 3345 | + { |
|
| 2847 | 3346 | $nameSpace[$singleNameSpace['type']]=$singleNameSpace; |
| 2848 | 3347 | } |
| 2849 | 3348 | unset($nameSpaceTmp); |
| 2850 | 3349 | |
| 2851 | 3350 | //error_log(__METHOD__.__LINE__.array2string($nameSpace)); |
| 2852 | 3351 | // Get special use folders |
| 2853 | - if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders |
|
| 3352 | + if (!isset(self::$specialUseFolders)) |
|
| 3353 | + { |
|
| 3354 | + $this->getSpecialUseFolders (); |
|
| 3355 | + } |
|
| 3356 | + // Set self::$specialUseFolders |
|
| 2854 | 3357 | // topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace |
| 2855 | - if ($_onlyTopLevel) // top level leaves |
|
| 3358 | + if ($_onlyTopLevel) |
|
| 3359 | + { |
|
| 3360 | + // top level leaves |
|
| 2856 | 3361 | { |
| 2857 | 3362 | // Get top mailboxes of icServer |
| 2858 | 3363 | $topFolders = $this->icServer->getMailboxes("", 2, true); |
| 3364 | + } |
|
| 2859 | 3365 | // Trigger examination of namespace to retrieve |
| 2860 | 3366 | // folders located in other and shared; needed only for some servers |
| 2861 | - if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail'); |
|
| 3367 | + if (is_null(self::$mailConfig)) |
|
| 3368 | + { |
|
| 3369 | + self::$mailConfig = Config::read('mail'); |
|
| 3370 | + } |
|
| 2862 | 3371 | if (self::$mailConfig['examineNamespace']) |
| 2863 | 3372 | { |
| 2864 | 3373 | $prefixes=array(); |
| 2865 | 3374 | if (is_array($nameSpace)) |
| 2866 | 3375 | { |
| 2867 | - foreach($nameSpace as $k => $singleNameSpace) { |
|
| 3376 | + foreach($nameSpace as $k => $singleNameSpace) |
|
| 3377 | + { |
|
| 2868 | 3378 | $type = $singleNameSpace['type']; |
| 2869 | 3379 | |
| 2870 | - if(is_array($singleNameSpace) && $singleNameSpace['prefix']){ |
|
| 3380 | + if(is_array($singleNameSpace) && $singleNameSpace['prefix']) |
|
| 3381 | + { |
|
| 2871 | 3382 | $prefixes[$type] = $singleNameSpace['prefix']; |
| 2872 | 3383 | //regard extra care for nameSpacequeries when configured AND respect $_search |
| 2873 | 3384 | $result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true); |
@@ -2943,7 +3454,10 @@ discard block |
||
| 2943 | 3454 | $nFolders [$path] = $folder; |
| 2944 | 3455 | } |
| 2945 | 3456 | } |
| 2946 | - if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder')); |
|
| 3457 | + if (is_array($aFolders)) |
|
| 3458 | + { |
|
| 3459 | + uasort ($aFolders, array($this,'sortByAutofolder')); |
|
| 3460 | + } |
|
| 2947 | 3461 | //ksort($aFolders); |
| 2948 | 3462 | |
| 2949 | 3463 | // Sort none auto folders base on mailbox name |
@@ -2953,12 +3467,17 @@ discard block |
||
| 2953 | 3467 | } |
| 2954 | 3468 | else |
| 2955 | 3469 | { |
| 2956 | - if (is_array($subFolders)) ksort($subFolders); |
|
| 3470 | + if (is_array($subFolders)) |
|
| 3471 | + { |
|
| 3472 | + ksort($subFolders); |
|
| 3473 | + } |
|
| 2957 | 3474 | } |
| 2958 | 3475 | $folders = array_merge($folders,(array)$mainFolder, (array)$subFolders); |
| 2959 | 3476 | } |
| 2960 | 3477 | } |
| 2961 | - elseif ($_nodePath) // single node |
|
| 3478 | + elseif ($_nodePath) |
|
| 3479 | + { |
|
| 3480 | + // single node |
|
| 2962 | 3481 | { |
| 2963 | 3482 | switch ($_search) |
| 2964 | 3483 | { |
@@ -2966,6 +3485,7 @@ discard block |
||
| 2966 | 3485 | case 0: |
| 2967 | 3486 | case 2: |
| 2968 | 3487 | $path = $_nodePath.''.$delimiter; |
| 3488 | + } |
|
| 2969 | 3489 | break; |
| 2970 | 3490 | // Node itself |
| 2971 | 3491 | // shouldn't contain next level delimiter |
@@ -2984,11 +3504,14 @@ discard block |
||
| 2984 | 3504 | |
| 2985 | 3505 | uasort($folders,array($this,'sortByMailbox'));//ksort($folders); |
| 2986 | 3506 | } |
| 2987 | - elseif(!$_nodePath) // all |
|
| 3507 | + elseif(!$_nodePath) |
|
| 3508 | + { |
|
| 3509 | + // all |
|
| 2988 | 3510 | { |
| 2989 | 3511 | if ($_subscribedOnly) |
| 2990 | 3512 | { |
| 2991 | 3513 | $folders = $this->icServer->listSubscribedMailboxes('', 0, true); |
| 3514 | + } |
|
| 2992 | 3515 | } |
| 2993 | 3516 | else |
| 2994 | 3517 | { |
@@ -3000,7 +3523,10 @@ discard block |
||
| 3000 | 3523 | { |
| 3001 | 3524 | // SORTING FOLDERS |
| 3002 | 3525 | //self::$debugTimes=true; |
| 3003 | - if (self::$debugTimes) $starttime = microtime (true); |
|
| 3526 | + if (self::$debugTimes) |
|
| 3527 | + { |
|
| 3528 | + $starttime = microtime (true); |
|
| 3529 | + } |
|
| 3004 | 3530 | // Merge of all auto folders and specialusefolders |
| 3005 | 3531 | $autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders)))); |
| 3006 | 3532 | uasort($folders,array($this,'sortByMailbox'));//ksort($folders); |
@@ -3010,73 +3536,103 @@ discard block |
||
| 3010 | 3536 | $isGoogleMail=false; |
| 3011 | 3537 | foreach($autoFoldersTmp as $afk=>$aF) |
| 3012 | 3538 | { |
| 3013 | - if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false); |
|
| 3539 | + if (!isset($mySpecialUseFolders[$aF]) && $aF) |
|
| 3540 | + { |
|
| 3541 | + $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false); |
|
| 3542 | + } |
|
| 3014 | 3543 | //error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]); |
| 3015 | 3544 | } |
| 3016 | 3545 | //error_log(array2string($mySpecialUseFolders)); |
| 3017 | - foreach ($tmpFolders as $k => $f) { |
|
| 3546 | + foreach ($tmpFolders as $k => $f) |
|
| 3547 | + { |
|
| 3018 | 3548 | $sorted=false; |
| 3019 | - if (strtoupper(substr($k,0,5))=='INBOX') { |
|
| 3020 | - if (strtoupper($k)=='INBOX') { |
|
| 3549 | + if (strtoupper(substr($k,0,5))=='INBOX') |
|
| 3550 | + { |
|
| 3551 | + if (strtoupper($k)=='INBOX') |
|
| 3552 | + { |
|
| 3021 | 3553 | //error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k); |
| 3022 | 3554 | $inboxFolderObject[$k]=$f; |
| 3023 | 3555 | unset($folders[$k]); |
| 3024 | 3556 | $sorted=true; |
| 3025 | - } else { |
|
| 3557 | + } |
|
| 3558 | + else |
|
| 3559 | + { |
|
| 3026 | 3560 | $isAutoFolder=false; |
| 3027 | 3561 | foreach($autoFoldersTmp as $afk=>$aF) |
| 3028 | 3562 | { |
| 3029 | 3563 | //error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]); |
| 3030 | 3564 | if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/ |
| 3031 | 3565 | ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder |
| 3032 | - stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder |
|
| 3566 | + stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) |
|
| 3567 | + { |
|
| 3568 | + // k is parent of an autofolder |
|
| 3033 | 3569 | { |
| 3034 | 3570 | //error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]); |
| 3035 | 3571 | $isAutoFolder=true; |
| 3572 | + } |
|
| 3036 | 3573 | $autoFolderObjects[$k]=$f; |
| 3037 | 3574 | break; |
| 3038 | 3575 | } |
| 3039 | 3576 | } |
| 3040 | - if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f; |
|
| 3577 | + if ($isAutoFolder==false) |
|
| 3578 | + { |
|
| 3579 | + $inboxSubFolderObjects[$k]=$f; |
|
| 3580 | + } |
|
| 3041 | 3581 | unset($folders[$k]); |
| 3042 | 3582 | $sorted=true; |
| 3043 | 3583 | } |
| 3044 | - } elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') { |
|
| 3584 | + } |
|
| 3585 | + elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') |
|
| 3586 | + { |
|
| 3045 | 3587 | $isGoogleMail=true; |
| 3046 | - if (strtoupper($k)=='[GOOGLE MAIL]') { |
|
| 3588 | + if (strtoupper($k)=='[GOOGLE MAIL]') |
|
| 3589 | + { |
|
| 3047 | 3590 | $googleMailFolderObject[$k]=$f; |
| 3048 | 3591 | unset($folders[$k]); |
| 3049 | 3592 | $sorted=true; |
| 3050 | - } else { |
|
| 3593 | + } |
|
| 3594 | + else |
|
| 3595 | + { |
|
| 3051 | 3596 | $isAutoFolder=false; |
| 3052 | 3597 | foreach($autoFoldersTmp as $afk=>$aF) |
| 3053 | 3598 | { |
| 3054 | 3599 | //error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]); |
| 3055 | 3600 | if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/ |
| 3056 | 3601 | ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder |
| 3057 | - stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder |
|
| 3602 | + stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) |
|
| 3603 | + { |
|
| 3604 | + // k is parent of an autofolder |
|
| 3058 | 3605 | { |
| 3059 | 3606 | //error_log($k.'->'.$mySpecialUseFolders[$aF]); |
| 3060 | 3607 | $isAutoFolder=true; |
| 3608 | + } |
|
| 3061 | 3609 | $googleAutoFolderObjects[$k]=$f; |
| 3062 | 3610 | break; |
| 3063 | 3611 | } |
| 3064 | 3612 | } |
| 3065 | - if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f; |
|
| 3613 | + if ($isAutoFolder==false) |
|
| 3614 | + { |
|
| 3615 | + $googleSubFolderObjects[$k]=$f; |
|
| 3616 | + } |
|
| 3066 | 3617 | unset($folders[$k]); |
| 3067 | 3618 | $sorted=true; |
| 3068 | 3619 | } |
| 3069 | - } else { |
|
| 3620 | + } |
|
| 3621 | + else |
|
| 3622 | + { |
|
| 3070 | 3623 | $isAutoFolder=false; |
| 3071 | 3624 | foreach($autoFoldersTmp as $afk=>$aF) |
| 3072 | 3625 | { |
| 3073 | 3626 | //error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]); |
| 3074 | 3627 | if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/ |
| 3075 | 3628 | ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder |
| 3076 | - stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder |
|
| 3629 | + stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) |
|
| 3630 | + { |
|
| 3631 | + // k is parent of an autofolder |
|
| 3077 | 3632 | { |
| 3078 | 3633 | //error_log($k.'->'.$mySpecialUseFolders[$aF]); |
| 3079 | 3634 | $isAutoFolder=true; |
| 3635 | + } |
|
| 3080 | 3636 | $autoFolderObjects[$k]=$f; |
| 3081 | 3637 | unset($folders[$k]); |
| 3082 | 3638 | $sorted=true; |
@@ -3092,7 +3648,8 @@ discard block |
||
| 3092 | 3648 | if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix']) |
| 3093 | 3649 | { |
| 3094 | 3650 | if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']|| |
| 3095 | - substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) { |
|
| 3651 | + substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) |
|
| 3652 | + { |
|
| 3096 | 3653 | //error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k); |
| 3097 | 3654 | $typeFolderObject[$type][$k]=$f; |
| 3098 | 3655 | unset($folders[$k]); |
@@ -3119,9 +3676,12 @@ discard block |
||
| 3119 | 3676 | } |
| 3120 | 3677 | } |
| 3121 | 3678 | //error_log(__METHOD__.__LINE__.array2string($autoFolderObjects)); |
| 3122 | - if (!$isGoogleMail) { |
|
| 3679 | + if (!$isGoogleMail) |
|
| 3680 | + { |
|
| 3123 | 3681 | $folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']); |
| 3124 | - } else { |
|
| 3682 | + } |
|
| 3683 | + else |
|
| 3684 | + { |
|
| 3125 | 3685 | // avoid calling sortByAutoFolder as it is not regarding subfolders |
| 3126 | 3686 | $gAutoFolderObjectsTmp = $googleAutoFolderObjects; |
| 3127 | 3687 | unset($googleAutoFolderObjects); |
@@ -3138,7 +3698,10 @@ discard block |
||
| 3138 | 3698 | } |
| 3139 | 3699 | $folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']); |
| 3140 | 3700 | } |
| 3141 | - if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:'); |
|
| 3701 | + if (self::$debugTimes) |
|
| 3702 | + { |
|
| 3703 | + self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:'); |
|
| 3704 | + } |
|
| 3142 | 3705 | //self::$debugTimes=false; |
| 3143 | 3706 | } |
| 3144 | 3707 | // Get counter information and add them to each fetched folders array |
@@ -3188,7 +3751,13 @@ discard block |
||
| 3188 | 3751 | $rv = false; |
| 3189 | 3752 | foreach ($haystack as $k => $v) |
| 3190 | 3753 | { |
| 3191 | - foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;} |
|
| 3754 | + foreach($v as &$sv) |
|
| 3755 | + { |
|
| 3756 | +if (trim($sv)==trim($needle)) |
|
| 3757 | + { |
|
| 3758 | + return $k; |
|
| 3759 | + } |
|
| 3760 | + } |
|
| 3192 | 3761 | } |
| 3193 | 3762 | return $rv; |
| 3194 | 3763 | } |
@@ -3215,7 +3784,10 @@ discard block |
||
| 3215 | 3784 | */ |
| 3216 | 3785 | static function pathToFolderData ($_path, $_hDelimiter) |
| 3217 | 3786 | { |
| 3218 | - if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path; |
|
| 3787 | + if (!strpos($_path, self::DELIMITER)) |
|
| 3788 | + { |
|
| 3789 | + $_path = self::DELIMITER.$_path; |
|
| 3790 | + } |
|
| 3219 | 3791 | list(,$path) = explode(self::DELIMITER, $_path); |
| 3220 | 3792 | $path_chain = $parts = explode($_hDelimiter, $path); |
| 3221 | 3793 | $name = array_pop($parts); |
@@ -3244,7 +3816,10 @@ discard block |
||
| 3244 | 3816 | $b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']); |
| 3245 | 3817 | $pos1 = array_search(trim($a['name']),self::$autoFolders); |
| 3246 | 3818 | $pos2 = array_search(trim($b['name']),self::$autoFolders); |
| 3247 | - if ($pos1 == $pos2) return 0; |
|
| 3819 | + if ($pos1 == $pos2) |
|
| 3820 | + { |
|
| 3821 | + return 0; |
|
| 3822 | + } |
|
| 3248 | 3823 | return ($pos1 < $pos2) ? -1 : 1; |
| 3249 | 3824 | } |
| 3250 | 3825 | |
@@ -3275,7 +3850,10 @@ discard block |
||
| 3275 | 3850 | // 0, 1 und -1 |
| 3276 | 3851 | $pos1 = array_search(trim($a->shortFolderName),self::$autoFolders); |
| 3277 | 3852 | $pos2 = array_search(trim($b->shortFolderName),self::$autoFolders); |
| 3278 | - if ($pos1 == $pos2) return 0; |
|
| 3853 | + if ($pos1 == $pos2) |
|
| 3854 | + { |
|
| 3855 | + return 0; |
|
| 3856 | + } |
|
| 3279 | 3857 | return ($pos1 < $pos2) ? -1 : 1; |
| 3280 | 3858 | } |
| 3281 | 3859 | |
@@ -3296,11 +3874,18 @@ discard block |
||
| 3296 | 3874 | } |
| 3297 | 3875 | catch (\Exception $e) |
| 3298 | 3876 | { |
| 3299 | - if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage()); |
|
| 3877 | + if (self::$debug) |
|
| 3878 | + { |
|
| 3879 | + error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage()); |
|
| 3880 | + } |
|
| 3300 | 3881 | return false; |
| 3301 | 3882 | } |
| 3302 | - if(is_array($folderStatus)) { |
|
| 3303 | - if ($_returnObject===false) return $folderStatus; |
|
| 3883 | + if(is_array($folderStatus)) |
|
| 3884 | + { |
|
| 3885 | + if ($_returnObject===false) |
|
| 3886 | + { |
|
| 3887 | + return $folderStatus; |
|
| 3888 | + } |
|
| 3304 | 3889 | $status = new \stdClass; |
| 3305 | 3890 | $status->messages = $folderStatus['MESSAGES']; |
| 3306 | 3891 | $status->unseen = $folderStatus['UNSEEN']; |
@@ -3327,7 +3912,8 @@ discard block |
||
| 3327 | 3912 | { |
| 3328 | 3913 | #echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>"; |
| 3329 | 3914 | $maxreclevel=25; |
| 3330 | - if ($reclevel > $maxreclevel) { |
|
| 3915 | + if ($reclevel > $maxreclevel) |
|
| 3916 | + { |
|
| 3331 | 3917 | error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter "); |
| 3332 | 3918 | return array(); |
| 3333 | 3919 | } |
@@ -3341,7 +3927,8 @@ discard block |
||
| 3341 | 3927 | //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter)); |
| 3342 | 3928 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx)); |
| 3343 | 3929 | // Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /)) |
| 3344 | - 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"]))) { |
|
| 3930 | + 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"]))) |
|
| 3931 | + { |
|
| 3345 | 3932 | // if there are children fetch them |
| 3346 | 3933 | //echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>"; |
| 3347 | 3934 | |
@@ -3349,7 +3936,8 @@ discard block |
||
| 3349 | 3936 | //$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false); |
| 3350 | 3937 | //_debug_array($buff); |
| 3351 | 3938 | $allMailboxes = array(); |
| 3352 | - foreach ($buff as $mbxname) { |
|
| 3939 | + foreach ($buff as $mbxname) |
|
| 3940 | + { |
|
| 3353 | 3941 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname)); |
| 3354 | 3942 | $mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']); |
| 3355 | 3943 | #echo "About to recur in level $reclevel:".$mbxname."<br>"; |
@@ -3358,9 +3946,14 @@ discard block |
||
| 3358 | 3946 | $allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel)); |
| 3359 | 3947 | } |
| 3360 | 3948 | } |
| 3361 | - 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']; |
|
| 3949 | + if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) |
|
| 3950 | + { |
|
| 3951 | + $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX']; |
|
| 3952 | + } |
|
| 3362 | 3953 | return $allMailboxes; |
| 3363 | - } else { |
|
| 3954 | + } |
|
| 3955 | + else |
|
| 3956 | + { |
|
| 3364 | 3957 | return array($_mailbox); |
| 3365 | 3958 | } |
| 3366 | 3959 | } |
@@ -3384,14 +3977,21 @@ discard block |
||
| 3384 | 3977 | 'Outbox' => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'), |
| 3385 | 3978 | 'Archive' => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'), |
| 3386 | 3979 | ); |
| 3387 | - if ($_type == 'Templates') $_type = 'Template'; // for some reason self::$autofolders uses 'Templates'! |
|
| 3980 | + if ($_type == 'Templates') |
|
| 3981 | + { |
|
| 3982 | + $_type = 'Template'; |
|
| 3983 | + } |
|
| 3984 | + // for some reason self::$autofolders uses 'Templates'! |
|
| 3388 | 3985 | $created = false; |
| 3389 | 3986 | if (!isset($types[$_type])) |
| 3390 | 3987 | { |
| 3391 | 3988 | error_log(__METHOD__.' ('.__LINE__.') '.' '.$_type.' not supported for '.__METHOD__); |
| 3392 | 3989 | return false; |
| 3393 | 3990 | } |
| 3394 | - if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) self::$specialUseFolders = $this->getSpecialUseFolders(); |
|
| 3991 | + if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) |
|
| 3992 | + { |
|
| 3993 | + self::$specialUseFolders = $this->getSpecialUseFolders(); |
|
| 3994 | + } |
|
| 3395 | 3995 | |
| 3396 | 3996 | //highest precedence |
| 3397 | 3997 | try |
@@ -3401,25 +4001,39 @@ discard block |
||
| 3401 | 4001 | catch (\Exception $e) |
| 3402 | 4002 | { |
| 3403 | 4003 | // we know that outbox is not supported, but we use this here, as we autocreate expected SpecialUseFolders in this function |
| 3404 | - if ($_type != 'Outbox') error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage()); |
|
| 4004 | + if ($_type != 'Outbox') |
|
| 4005 | + { |
|
| 4006 | + error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage()); |
|
| 4007 | + } |
|
| 3405 | 4008 | $_folderName = false; |
| 3406 | 4009 | } |
| 3407 | 4010 | // do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist |
| 3408 | - if ($_type == 'Archive') { |
|
| 3409 | - if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) { |
|
| 4011 | + if ($_type == 'Archive') |
|
| 4012 | + { |
|
| 4013 | + if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) |
|
| 4014 | + { |
|
| 3410 | 4015 | return false; |
| 3411 | - } else { |
|
| 4016 | + } |
|
| 4017 | + else |
|
| 4018 | + { |
|
| 3412 | 4019 | return $_folderName; |
| 3413 | 4020 | } |
| 3414 | 4021 | |
| 3415 | 4022 | } |
| 3416 | 4023 | // does the folder exist??? (is configured/preset, but non-existent) |
| 3417 | - if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) { |
|
| 4024 | + if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) |
|
| 4025 | + { |
|
| 3418 | 4026 | try |
| 3419 | 4027 | { |
| 3420 | 4028 | $error = null; |
| 3421 | - if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true; |
|
| 3422 | - if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error); |
|
| 4029 | + if (($_folderName = $this->createFolder('', $_folderName, $error))) |
|
| 4030 | + { |
|
| 4031 | + $created = true; |
|
| 4032 | + } |
|
| 4033 | + if ($error) |
|
| 4034 | + { |
|
| 4035 | + error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error); |
|
| 4036 | + } |
|
| 3423 | 4037 | } |
| 3424 | 4038 | catch(Exception $e) |
| 3425 | 4039 | { |
@@ -3428,9 +4042,16 @@ discard block |
||
| 3428 | 4042 | } |
| 3429 | 4043 | } |
| 3430 | 4044 | // not sure yet if false is the correct behavior on none |
| 3431 | - if ($_folderName =='none') return 'none' ; //false; |
|
| 4045 | + if ($_folderName =='none') |
|
| 4046 | + { |
|
| 4047 | + return 'none' ; |
|
| 4048 | + } |
|
| 4049 | + //false; |
|
| 3432 | 4050 | //no (valid) folder found yet; try specialUseFolders |
| 3433 | - if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f; |
|
| 4051 | + if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) |
|
| 4052 | + { |
|
| 4053 | + $_folderName = $f; |
|
| 4054 | + } |
|
| 3434 | 4055 | //no specialUseFolder; try some Defaults |
| 3435 | 4056 | if (empty($_folderName) && isset($types[$_type])) |
| 3436 | 4057 | { |
@@ -3456,7 +4077,10 @@ discard block |
||
| 3456 | 4077 | $error = null; |
| 3457 | 4078 | $this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error); |
| 3458 | 4079 | $_folderName = $prefix.$types[$_type]['autoFolderName']; |
| 3459 | - if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error); |
|
| 4080 | + if ($error) |
|
| 4081 | + { |
|
| 4082 | + error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error); |
|
| 4083 | + } |
|
| 3460 | 4084 | } |
| 3461 | 4085 | catch(Exception $e) |
| 3462 | 4086 | { |
@@ -3559,25 +4183,35 @@ discard block |
||
| 3559 | 4183 | function isSentFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false) |
| 3560 | 4184 | { |
| 3561 | 4185 | $sentFolder = $this->getSentFolder($_checkexistance); |
| 3562 | - if(empty($sentFolder)) { |
|
| 4186 | + if(empty($sentFolder)) |
|
| 4187 | + { |
|
| 3563 | 4188 | return false; |
| 3564 | 4189 | } |
| 3565 | 4190 | // does the folder exist??? |
| 3566 | - if ($_checkexistance && !$this->folderExists($_folderName)) { |
|
| 4191 | + if ($_checkexistance && !$this->folderExists($_folderName)) |
|
| 4192 | + { |
|
| 3567 | 4193 | return false; |
| 3568 | 4194 | } |
| 3569 | 4195 | |
| 3570 | 4196 | if ($_exactMatch) |
| 3571 | 4197 | { |
| 3572 | - if(false !== stripos($_folderName, $sentFolder)&& strlen($_folderName)==strlen($sentFolder)) { |
|
| 4198 | + if(false !== stripos($_folderName, $sentFolder)&& strlen($_folderName)==strlen($sentFolder)) |
|
| 4199 | + { |
|
| 3573 | 4200 | return true; |
| 3574 | - } else { |
|
| 4201 | + } |
|
| 4202 | + else |
|
| 4203 | + { |
|
| 3575 | 4204 | return false; |
| 3576 | 4205 | } |
| 3577 | - } else { |
|
| 3578 | - if(false !== stripos($_folderName, $sentFolder)) { |
|
| 4206 | + } |
|
| 4207 | + else |
|
| 4208 | + { |
|
| 4209 | + if(false !== stripos($_folderName, $sentFolder)) |
|
| 4210 | + { |
|
| 3579 | 4211 | return true; |
| 3580 | - } else { |
|
| 4212 | + } |
|
| 4213 | + else |
|
| 4214 | + { |
|
| 3581 | 4215 | return false; |
| 3582 | 4216 | } |
| 3583 | 4217 | } |
@@ -3592,23 +4226,33 @@ discard block |
||
| 3592 | 4226 | */ |
| 3593 | 4227 | function isOutbox($_folderName, $_checkexistance=TRUE, $_exactMatch=false) |
| 3594 | 4228 | { |
| 3595 | - if (stripos($_folderName, 'Outbox')===false) { |
|
| 4229 | + if (stripos($_folderName, 'Outbox')===false) |
|
| 4230 | + { |
|
| 3596 | 4231 | return false; |
| 3597 | 4232 | } |
| 3598 | 4233 | // does the folder exist??? |
| 3599 | - if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) { |
|
| 4234 | + if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) |
|
| 4235 | + { |
|
| 3600 | 4236 | $outboxFolder = $this->getOutboxFolder($_checkexistance); |
| 3601 | 4237 | if ($_exactMatch) |
| 3602 | 4238 | { |
| 3603 | - if(false !== stripos($_folderName, $outboxFolder)&& strlen($_folderName)==strlen($outboxFolder)) { |
|
| 4239 | + if(false !== stripos($_folderName, $outboxFolder)&& strlen($_folderName)==strlen($outboxFolder)) |
|
| 4240 | + { |
|
| 3604 | 4241 | return true; |
| 3605 | - } else { |
|
| 4242 | + } |
|
| 4243 | + else |
|
| 4244 | + { |
|
| 3606 | 4245 | return false; |
| 3607 | 4246 | } |
| 3608 | - } else { |
|
| 3609 | - if(false !== stripos($_folderName, $outboxFolder)) { |
|
| 4247 | + } |
|
| 4248 | + else |
|
| 4249 | + { |
|
| 4250 | + if(false !== stripos($_folderName, $outboxFolder)) |
|
| 4251 | + { |
|
| 3610 | 4252 | return true; |
| 3611 | - } else { |
|
| 4253 | + } |
|
| 4254 | + else |
|
| 4255 | + { |
|
| 3612 | 4256 | return false; |
| 3613 | 4257 | } |
| 3614 | 4258 | } |
@@ -3626,25 +4270,38 @@ discard block |
||
| 3626 | 4270 | function isDraftFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false) |
| 3627 | 4271 | { |
| 3628 | 4272 | $draftFolder = $this->getDraftFolder($_checkexistance); |
| 3629 | - if(empty($draftFolder)) { |
|
| 4273 | + if(empty($draftFolder)) |
|
| 4274 | + { |
|
| 3630 | 4275 | return false; |
| 3631 | 4276 | } |
| 3632 | 4277 | // does the folder exist??? |
| 3633 | - if ($_checkexistance && !$this->folderExists($_folderName)) { |
|
| 4278 | + if ($_checkexistance && !$this->folderExists($_folderName)) |
|
| 4279 | + { |
|
| 3634 | 4280 | return false; |
| 3635 | 4281 | } |
| 3636 | - if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8; |
|
| 4282 | + if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) |
|
| 4283 | + { |
|
| 4284 | + $_folderName = $_folderName->utf8; |
|
| 4285 | + } |
|
| 3637 | 4286 | if ($_exactMatch) |
| 3638 | 4287 | { |
| 3639 | - if(false !== stripos($_folderName, $draftFolder)&& strlen($_folderName)==strlen($draftFolder)) { |
|
| 4288 | + if(false !== stripos($_folderName, $draftFolder)&& strlen($_folderName)==strlen($draftFolder)) |
|
| 4289 | + { |
|
| 4290 | + return true; |
|
| 4291 | + } |
|
| 4292 | + else |
|
| 4293 | + { |
|
| 4294 | + return false; |
|
| 4295 | + } |
|
| 4296 | + } |
|
| 4297 | + else |
|
| 4298 | + { |
|
| 4299 | + if(false !== stripos($_folderName, $draftFolder)) |
|
| 4300 | + { |
|
| 3640 | 4301 | return true; |
| 3641 | - } else { |
|
| 3642 | - return false; |
|
| 3643 | 4302 | } |
| 3644 | - } else { |
|
| 3645 | - if(false !== stripos($_folderName, $draftFolder)) { |
|
| 3646 | - return true; |
|
| 3647 | - } else { |
|
| 4303 | + else |
|
| 4304 | + { |
|
| 3648 | 4305 | return false; |
| 3649 | 4306 | } |
| 3650 | 4307 | } |
@@ -3660,25 +4317,35 @@ discard block |
||
| 3660 | 4317 | function isTrashFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false) |
| 3661 | 4318 | { |
| 3662 | 4319 | $trashFolder = $this->getTrashFolder($_checkexistance); |
| 3663 | - if(empty($trashFolder)) { |
|
| 4320 | + if(empty($trashFolder)) |
|
| 4321 | + { |
|
| 3664 | 4322 | return false; |
| 3665 | 4323 | } |
| 3666 | 4324 | // does the folder exist??? |
| 3667 | - if ($_checkexistance && !$this->folderExists($_folderName)) { |
|
| 4325 | + if ($_checkexistance && !$this->folderExists($_folderName)) |
|
| 4326 | + { |
|
| 3668 | 4327 | return false; |
| 3669 | 4328 | } |
| 3670 | 4329 | |
| 3671 | 4330 | if ($_exactMatch) |
| 3672 | 4331 | { |
| 3673 | - if(false !== stripos($_folderName, $trashFolder)&& strlen($_folderName)==strlen($trashFolder)) { |
|
| 4332 | + if(false !== stripos($_folderName, $trashFolder)&& strlen($_folderName)==strlen($trashFolder)) |
|
| 4333 | + { |
|
| 3674 | 4334 | return true; |
| 3675 | - } else { |
|
| 4335 | + } |
|
| 4336 | + else |
|
| 4337 | + { |
|
| 3676 | 4338 | return false; |
| 3677 | 4339 | } |
| 3678 | - } else { |
|
| 3679 | - if(false !== stripos($_folderName, $trashFolder)) { |
|
| 4340 | + } |
|
| 4341 | + else |
|
| 4342 | + { |
|
| 4343 | + if(false !== stripos($_folderName, $trashFolder)) |
|
| 4344 | + { |
|
| 3680 | 4345 | return true; |
| 3681 | - } else { |
|
| 4346 | + } |
|
| 4347 | + else |
|
| 4348 | + { |
|
| 3682 | 4349 | return false; |
| 3683 | 4350 | } |
| 3684 | 4351 | } |
@@ -3694,24 +4361,34 @@ discard block |
||
| 3694 | 4361 | function isTemplateFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false) |
| 3695 | 4362 | { |
| 3696 | 4363 | $templateFolder = $this->getTemplateFolder($_checkexistance); |
| 3697 | - if(empty($templateFolder)) { |
|
| 4364 | + if(empty($templateFolder)) |
|
| 4365 | + { |
|
| 3698 | 4366 | return false; |
| 3699 | 4367 | } |
| 3700 | 4368 | // does the folder exist??? |
| 3701 | - if ($_checkexistance && !$this->folderExists($_folderName)) { |
|
| 4369 | + if ($_checkexistance && !$this->folderExists($_folderName)) |
|
| 4370 | + { |
|
| 3702 | 4371 | return false; |
| 3703 | 4372 | } |
| 3704 | 4373 | if ($_exactMatch) |
| 3705 | 4374 | { |
| 3706 | - if(false !== stripos($_folderName, $templateFolder)&& strlen($_folderName)==strlen($templateFolder)) { |
|
| 4375 | + if(false !== stripos($_folderName, $templateFolder)&& strlen($_folderName)==strlen($templateFolder)) |
|
| 4376 | + { |
|
| 3707 | 4377 | return true; |
| 3708 | - } else { |
|
| 4378 | + } |
|
| 4379 | + else |
|
| 4380 | + { |
|
| 3709 | 4381 | return false; |
| 3710 | 4382 | } |
| 3711 | - } else { |
|
| 3712 | - if(false !== stripos($_folderName, $templateFolder)) { |
|
| 4383 | + } |
|
| 4384 | + else |
|
| 4385 | + { |
|
| 4386 | + if(false !== stripos($_folderName, $templateFolder)) |
|
| 4387 | + { |
|
| 3713 | 4388 | return true; |
| 3714 | - } else { |
|
| 4389 | + } |
|
| 4390 | + else |
|
| 4391 | + { |
|
| 3715 | 4392 | return false; |
| 3716 | 4393 | } |
| 3717 | 4394 | } |
@@ -3730,15 +4407,27 @@ discard block |
||
| 3730 | 4407 | if (empty($_folder)) |
| 3731 | 4408 | { |
| 3732 | 4409 | // this error is more or less without significance, unless we force the check |
| 3733 | - if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace()); |
|
| 4410 | + if ($_forceCheck===true) |
|
| 4411 | + { |
|
| 4412 | + error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace()); |
|
| 4413 | + } |
|
| 3734 | 4414 | return false; |
| 3735 | 4415 | } |
| 3736 | 4416 | // when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder |
| 3737 | - if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true; |
|
| 3738 | - if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder = $_folder->utf8; |
|
| 4417 | + if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) |
|
| 4418 | + { |
|
| 4419 | + return true; |
|
| 4420 | + } |
|
| 4421 | + if (is_a($_folder,"Horde_Imap_Client_Mailbox")) |
|
| 4422 | + { |
|
| 4423 | + $_folder = $_folder->utf8; |
|
| 4424 | + } |
|
| 3739 | 4425 | // reduce traffic within the Instance per User; Expire every 5 hours |
| 3740 | 4426 | //error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace()); |
| 3741 | - if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5); |
|
| 4427 | + if (is_null($folderInfo)) |
|
| 4428 | + { |
|
| 4429 | + $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5); |
|
| 4430 | + } |
|
| 3742 | 4431 | //error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo)); |
| 3743 | 4432 | if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false) |
| 3744 | 4433 | { |
@@ -3756,7 +4445,8 @@ discard block |
||
| 3756 | 4445 | |
| 3757 | 4446 | // does the folder exist??? |
| 3758 | 4447 | //error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server')); |
| 3759 | - if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) { |
|
| 4448 | + if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) |
|
| 4449 | + { |
|
| 3760 | 4450 | //error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID); |
| 3761 | 4451 | //return false; |
| 3762 | 4452 | //try to connect |
@@ -3797,9 +4487,12 @@ discard block |
||
| 3797 | 4487 | |
| 3798 | 4488 | $this->icServer->openMailbox($folderName); |
| 3799 | 4489 | |
| 3800 | - if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") { |
|
| 4490 | + if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") |
|
| 4491 | + { |
|
| 3801 | 4492 | $this->deleteMessages('all',$folderName,'remove_immediately'); |
| 3802 | - } else { |
|
| 4493 | + } |
|
| 4494 | + else |
|
| 4495 | + { |
|
| 3803 | 4496 | $this->icServer->expunge($folderName); |
| 3804 | 4497 | } |
| 3805 | 4498 | } |
@@ -3818,10 +4511,16 @@ discard block |
||
| 3818 | 4511 | { |
| 3819 | 4512 | //error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod); |
| 3820 | 4513 | $oldMailbox = ''; |
| 3821 | - if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox']; |
|
| 4514 | + if (is_null($_folder) || empty($_folder)) |
|
| 4515 | + { |
|
| 4516 | + $_folder = $this->sessionData['mailbox']; |
|
| 4517 | + } |
|
| 3822 | 4518 | if (empty($_messageUID)) |
| 3823 | 4519 | { |
| 3824 | - if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID)); |
|
| 4520 | + if (self::$debug) |
|
| 4521 | + { |
|
| 4522 | + error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID)); |
|
| 4523 | + } |
|
| 3825 | 4524 | return false; |
| 3826 | 4525 | } |
| 3827 | 4526 | elseif ($_messageUID==='all') |
@@ -3831,32 +4530,48 @@ discard block |
||
| 3831 | 4530 | else |
| 3832 | 4531 | { |
| 3833 | 4532 | $uidsToDelete = new Horde_Imap_Client_Ids(); |
| 3834 | - if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID; |
|
| 4533 | + if (!(is_object($_messageUID) || is_array($_messageUID))) |
|
| 4534 | + { |
|
| 4535 | + $_messageUID = (array)$_messageUID; |
|
| 4536 | + } |
|
| 3835 | 4537 | $uidsToDelete->add($_messageUID); |
| 3836 | 4538 | } |
| 3837 | 4539 | $deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method |
| 3838 | - 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"); |
|
| 4540 | + if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately"))) |
|
| 4541 | + { |
|
| 4542 | + $deleteOptions = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted"); |
|
| 4543 | + } |
|
| 3839 | 4544 | //error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions); |
| 3840 | 4545 | $trashFolder = $this->getTrashFolder(); |
| 3841 | 4546 | $draftFolder = $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder']; |
| 3842 | 4547 | $templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder']; |
| 3843 | 4548 | if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") || |
| 3844 | - (strtolower($_folder) == strtolower($draftFolder))) { |
|
| 4549 | + (strtolower($_folder) == strtolower($draftFolder))) |
|
| 4550 | + { |
|
| 3845 | 4551 | $deleteOptions = "remove_immediately"; |
| 3846 | 4552 | } |
| 3847 | - if($this->icServer->getCurrentMailbox() != $_folder) { |
|
| 4553 | + if($this->icServer->getCurrentMailbox() != $_folder) |
|
| 4554 | + { |
|
| 3848 | 4555 | $oldMailbox = $this->icServer->getCurrentMailbox(); |
| 3849 | 4556 | $this->icServer->openMailbox($_folder); |
| 3850 | 4557 | } |
| 3851 | 4558 | //error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions); |
| 3852 | 4559 | $updateCache = false; |
| 3853 | - switch($deleteOptions) { |
|
| 4560 | + switch($deleteOptions) |
|
| 4561 | + { |
|
| 3854 | 4562 | case "move_to_trash": |
| 3855 | 4563 | //error_log(__METHOD__.' ('.__LINE__.') '); |
| 3856 | 4564 | $updateCache = true; |
| 3857 | - if(!empty($trashFolder)) { |
|
| 3858 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID)); |
|
| 3859 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']); |
|
| 4565 | + if(!empty($trashFolder)) |
|
| 4566 | + { |
|
| 4567 | + if (self::$debug) |
|
| 4568 | + { |
|
| 4569 | + error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID)); |
|
| 4570 | + } |
|
| 4571 | + if (self::$debug) |
|
| 4572 | + { |
|
| 4573 | + error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']); |
|
| 4574 | + } |
|
| 3860 | 4575 | // copy messages |
| 3861 | 4576 | try |
| 3862 | 4577 | { |
@@ -3872,7 +4587,10 @@ discard block |
||
| 3872 | 4587 | case "mark_as_deleted": |
| 3873 | 4588 | //error_log(__METHOD__.' ('.__LINE__.') '); |
| 3874 | 4589 | // mark messages as deleted |
| 3875 | - if (is_null($_messageUID)) $_messageUID='all'; |
|
| 4590 | + if (is_null($_messageUID)) |
|
| 4591 | + { |
|
| 4592 | + $_messageUID='all'; |
|
| 4593 | + } |
|
| 3876 | 4594 | foreach((array)$_messageUID as $key =>$uid) |
| 3877 | 4595 | { |
| 3878 | 4596 | //flag messages, that are flagged for deletion as seen too |
@@ -3880,7 +4598,10 @@ discard block |
||
| 3880 | 4598 | $flags = $this->getFlags($uid); |
| 3881 | 4599 | $this->flagMessages('delete', $uid, $_folder); |
| 3882 | 4600 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags)); |
| 3883 | - if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid; |
|
| 4601 | + if (strpos( array2string($flags),'Deleted')!==false) |
|
| 4602 | + { |
|
| 4603 | + $undelete[] = $uid; |
|
| 4604 | + } |
|
| 3884 | 4605 | unset($flags); |
| 3885 | 4606 | } |
| 3886 | 4607 | foreach((array)$undelete as $key =>$uid) |
@@ -3892,7 +4613,10 @@ discard block |
||
| 3892 | 4613 | case "remove_immediately": |
| 3893 | 4614 | //error_log(__METHOD__.' ('.__LINE__.') '); |
| 3894 | 4615 | $updateCache = true; |
| 3895 | - if (is_null($_messageUID)) $_messageUID='all'; |
|
| 4616 | + if (is_null($_messageUID)) |
|
| 4617 | + { |
|
| 4618 | + $_messageUID='all'; |
|
| 4619 | + } |
|
| 3896 | 4620 | if (is_object($_messageUID)) |
| 3897 | 4621 | { |
| 3898 | 4622 | $this->flagMessages('delete', $_messageUID, $_folder); |
@@ -3909,7 +4633,8 @@ discard block |
||
| 3909 | 4633 | $this->icServer->expunge($_folder); |
| 3910 | 4634 | break; |
| 3911 | 4635 | } |
| 3912 | - if($oldMailbox != '') { |
|
| 4636 | + if($oldMailbox != '') |
|
| 4637 | + { |
|
| 3913 | 4638 | $this->icServer->openMailbox($oldMailbox); |
| 3914 | 4639 | } |
| 3915 | 4640 | |
@@ -3923,11 +4648,15 @@ discard block |
||
| 3923 | 4648 | * |
| 3924 | 4649 | * @return null/array flags |
| 3925 | 4650 | */ |
| 3926 | - function getFlags ($_messageUID) { |
|
| 4651 | + function getFlags ($_messageUID) |
|
| 4652 | + { |
|
| 3927 | 4653 | try |
| 3928 | 4654 | { |
| 3929 | 4655 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 3930 | - if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID; |
|
| 4656 | + if (!(is_object($_messageUID) || is_array($_messageUID))) |
|
| 4657 | + { |
|
| 4658 | + $_messageUID = (array)$_messageUID; |
|
| 4659 | + } |
|
| 3931 | 4660 | $uidsToFetch->add($_messageUID); |
| 3932 | 4661 | $_folderName = $this->icServer->getCurrentMailbox(); |
| 3933 | 4662 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -3935,8 +4664,10 @@ discard block |
||
| 3935 | 4664 | $headersNew = $this->icServer->fetch($_folderName, $fquery, array( |
| 3936 | 4665 | 'ids' => $uidsToFetch, |
| 3937 | 4666 | )); |
| 3938 | - if (is_object($headersNew)) { |
|
| 3939 | - foreach($headersNew->ids() as $id) { |
|
| 4667 | + if (is_object($headersNew)) |
|
| 4668 | + { |
|
| 4669 | + foreach($headersNew->ids() as $id) |
|
| 4670 | + { |
|
| 3940 | 4671 | $_headerObject = $headersNew->get($id); |
| 3941 | 4672 | $flags = $_headerObject->getFlags(); |
| 3942 | 4673 | } |
@@ -3961,10 +4692,16 @@ discard block |
||
| 3961 | 4692 | */ |
| 3962 | 4693 | function getNotifyFlags ($_messageUID, $flags=null) |
| 3963 | 4694 | { |
| 3964 | - if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags)); |
|
| 4695 | + if (self::$debug) |
|
| 4696 | + { |
|
| 4697 | + error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags)); |
|
| 4698 | + } |
|
| 3965 | 4699 | try |
| 3966 | 4700 | { |
| 3967 | - if($flags===null) $flags = $this->getFlags($_messageUID); |
|
| 4701 | + if($flags===null) |
|
| 4702 | + { |
|
| 4703 | + $flags = $this->getFlags($_messageUID); |
|
| 4704 | + } |
|
| 3968 | 4705 | } |
| 3969 | 4706 | catch (\Exception $e) |
| 3970 | 4707 | { |
@@ -3972,10 +4709,14 @@ discard block |
||
| 3972 | 4709 | } |
| 3973 | 4710 | |
| 3974 | 4711 | if ( stripos( array2string($flags),'MDNSent')!==false) |
| 3975 | - return true; |
|
| 4712 | + { |
|
| 4713 | + return true; |
|
| 4714 | + } |
|
| 3976 | 4715 | |
| 3977 | 4716 | if ( stripos( array2string($flags),'MDNnotSent')!==false) |
| 3978 | - return false; |
|
| 4717 | + { |
|
| 4718 | + return false; |
|
| 4719 | + } |
|
| 3979 | 4720 | |
| 3980 | 4721 | return null; |
| 3981 | 4722 | } |
@@ -3996,7 +4737,10 @@ discard block |
||
| 3996 | 4737 | //error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']); |
| 3997 | 4738 | if (empty($_messageUID)) |
| 3998 | 4739 | { |
| 3999 | - if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID)); |
|
| 4740 | + if (self::$debug) |
|
| 4741 | + { |
|
| 4742 | + error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID)); |
|
| 4743 | + } |
|
| 4000 | 4744 | return false; |
| 4001 | 4745 | } |
| 4002 | 4746 | $this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox'])); |
@@ -4004,7 +4748,10 @@ discard block |
||
| 4004 | 4748 | if (is_array($_messageUID)&& count($_messageUID)>50) |
| 4005 | 4749 | { |
| 4006 | 4750 | $count = $this->getMailBoxCounters($folder,true); |
| 4007 | - if ($count->messages == count($_messageUID)) $_messageUID='all'; |
|
| 4751 | + if ($count->messages == count($_messageUID)) |
|
| 4752 | + { |
|
| 4753 | + $_messageUID='all'; |
|
| 4754 | + } |
|
| 4008 | 4755 | } |
| 4009 | 4756 | |
| 4010 | 4757 | if ($_messageUID==='all') |
@@ -4013,7 +4760,10 @@ discard block |
||
| 4013 | 4760 | } |
| 4014 | 4761 | else |
| 4015 | 4762 | { |
| 4016 | - if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID; |
|
| 4763 | + if (!(is_object($_messageUID) || is_array($_messageUID))) |
|
| 4764 | + { |
|
| 4765 | + $_messageUID = (array)$_messageUID; |
|
| 4766 | + } |
|
| 4017 | 4767 | $messageUIDs = array_chunk($_messageUID,50,true); |
| 4018 | 4768 | } |
| 4019 | 4769 | try |
@@ -4029,7 +4779,8 @@ discard block |
||
| 4029 | 4779 | $uidsToModify = new Horde_Imap_Client_Ids(); |
| 4030 | 4780 | $uidsToModify->add($uids); |
| 4031 | 4781 | } |
| 4032 | - switch($_flag) { |
|
| 4782 | + switch($_flag) |
|
| 4783 | + { |
|
| 4033 | 4784 | case "delete": |
| 4034 | 4785 | $ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify)); |
| 4035 | 4786 | break; |
@@ -4115,7 +4866,10 @@ discard block |
||
| 4115 | 4866 | { |
| 4116 | 4867 | error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage()); |
| 4117 | 4868 | } |
| 4118 | - if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8; |
|
| 4869 | + if ($folder instanceof Horde_Imap_Client_Mailbox) |
|
| 4870 | + { |
|
| 4871 | + $_folder = $folder->utf8; |
|
| 4872 | + } |
|
| 4119 | 4873 | //error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#'); |
| 4120 | 4874 | self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0; |
| 4121 | 4875 | |
@@ -4144,7 +4898,10 @@ discard block |
||
| 4144 | 4898 | //$deleteOptions = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"]; |
| 4145 | 4899 | if (empty($_messageUID)) |
| 4146 | 4900 | { |
| 4147 | - if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID)); |
|
| 4901 | + if (self::$debug) |
|
| 4902 | + { |
|
| 4903 | + error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID)); |
|
| 4904 | + } |
|
| 4148 | 4905 | return false; |
| 4149 | 4906 | } |
| 4150 | 4907 | elseif ($_messageUID==='all') |
@@ -4156,7 +4913,10 @@ discard block |
||
| 4156 | 4913 | { |
| 4157 | 4914 | //error_log(__METHOD__." Message(s): ".implode(',',$_messageUID)); |
| 4158 | 4915 | $uidsToMove = new Horde_Imap_Client_Ids(); |
| 4159 | - if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID; |
|
| 4916 | + if (!(is_object($_messageUID) || is_array($_messageUID))) |
|
| 4917 | + { |
|
| 4918 | + $_messageUID = (array)$_messageUID; |
|
| 4919 | + } |
|
| 4160 | 4920 | $uidsToMove->add($_messageUID); |
| 4161 | 4921 | } |
| 4162 | 4922 | $sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']); |
@@ -4178,12 +4938,14 @@ discard block |
||
| 4178 | 4938 | |
| 4179 | 4939 | //error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew)); |
| 4180 | 4940 | |
| 4181 | - if (is_object($headersNew)) { |
|
| 4941 | + if (is_object($headersNew)) |
|
| 4942 | + { |
|
| 4182 | 4943 | $c=0; |
| 4183 | 4944 | $retUid = new Horde_Imap_Client_Ids(); |
| 4184 | 4945 | // we copy chunks of 5 to avoid too much memory and/or server stress |
| 4185 | 4946 | // some servers seem not to allow/support the appendig of multiple messages. so we are down to one |
| 4186 | - foreach($headersNew as &$_headerObject) { |
|
| 4947 | + foreach($headersNew as &$_headerObject) |
|
| 4948 | + { |
|
| 4187 | 4949 | $c++; |
| 4188 | 4950 | $flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message |
| 4189 | 4951 | $date = $_headerObject->getImapDate(); |
@@ -4267,7 +5029,11 @@ discard block |
||
| 4267 | 5029 | { |
| 4268 | 5030 | try { |
| 4269 | 5031 | $date = new DateTime($_date); // parse date & time including timezone (throws exception, if not parsable) |
| 4270 | - if ($convert2usertime) $date->setUser(); // convert to user-time |
|
| 5032 | + if ($convert2usertime) |
|
| 5033 | + { |
|
| 5034 | + $date->setUser(); |
|
| 5035 | + } |
|
| 5036 | + // convert to user-time |
|
| 4271 | 5037 | $date2return = $date->format($format); |
| 4272 | 5038 | } |
| 4273 | 5039 | catch(\Exception $e) |
@@ -4299,9 +5065,15 @@ discard block |
||
| 4299 | 5065 | static function htmlentities($_string, $_charset=false) |
| 4300 | 5066 | { |
| 4301 | 5067 | //setting the charset (if not given) |
| 4302 | - if ($_charset===false) $_charset = self::$displayCharset; |
|
| 5068 | + if ($_charset===false) |
|
| 5069 | + { |
|
| 5070 | + $_charset = self::$displayCharset; |
|
| 5071 | + } |
|
| 4303 | 5072 | $string = @htmlentities($_string, ENT_QUOTES, $_charset, false); |
| 4304 | - if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false); |
|
| 5073 | + if (empty($string) && !empty($_string)) |
|
| 5074 | + { |
|
| 5075 | + $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false); |
|
| 5076 | + } |
|
| 4305 | 5077 | return $string; |
| 4306 | 5078 | } |
| 4307 | 5079 | |
@@ -4321,18 +5093,41 @@ discard block |
||
| 4321 | 5093 | $_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>'), |
| 4322 | 5094 | array('&', '<BR>', '<BR>', '<BR>', '</font></td>','<td>', '', '', '', ''),$_html); |
| 4323 | 5095 | //$_html = str_replace(array('&amp;'),array('&'),$_html); |
| 4324 | - if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags |
|
| 4325 | - if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head |
|
| 5096 | + if (stripos($_html,'style')!==false) |
|
| 5097 | + { |
|
| 5098 | + Mail\Html::replaceTagsCompletley($_html,'style'); |
|
| 5099 | + } |
|
| 5100 | + // clean out empty or pagewide style definitions / left over tags |
|
| 5101 | + if (stripos($_html,'head')!==false) |
|
| 5102 | + { |
|
| 5103 | + Mail\Html::replaceTagsCompletley($_html,'head'); |
|
| 5104 | + } |
|
| 5105 | + // Strip out stuff in head |
|
| 4326 | 5106 | //if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs |
| 4327 | 5107 | //if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs |
| 4328 | 5108 | //error_log(__METHOD__.' ('.__LINE__.') '.$_html); |
| 4329 | 5109 | |
| 4330 | - if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html); |
|
| 5110 | + if (get_magic_quotes_gpc() === 1) |
|
| 5111 | + { |
|
| 5112 | + $_html = stripslashes($_html); |
|
| 5113 | + } |
|
| 4331 | 5114 | // Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards |
| 4332 | - if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype'); |
|
| 4333 | - if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false); |
|
| 4334 | - if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false); |
|
| 4335 | - if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR'); |
|
| 5115 | + if (stripos($_html,'!doctype')!==false) |
|
| 5116 | + { |
|
| 5117 | + Mail\Html::replaceTagsCompletley($_html,'!doctype'); |
|
| 5118 | + } |
|
| 5119 | + if (stripos($_html,'?xml:namespace')!==false) |
|
| 5120 | + { |
|
| 5121 | + Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false); |
|
| 5122 | + } |
|
| 5123 | + if (stripos($_html,'?xml version')!==false) |
|
| 5124 | + { |
|
| 5125 | + Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false); |
|
| 5126 | + } |
|
| 5127 | + if (strpos($_html,'!CURSOR')!==false) |
|
| 5128 | + { |
|
| 5129 | + Mail\Html::replaceTagsCompletley($_html,'!CURSOR'); |
|
| 5130 | + } |
|
| 4336 | 5131 | // htmLawed filter only the 'body' |
| 4337 | 5132 | //preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches); |
| 4338 | 5133 | //if ($matches[2]) |
@@ -4371,8 +5166,10 @@ discard block |
||
| 4371 | 5166 | //$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1 |
| 4372 | 5167 | $CharsetFound=false; |
| 4373 | 5168 | //echo "#".$_mimePartObject->encoding.'#<br>'; |
| 4374 | - if(is_array($_mimePartObject->parameters)) { |
|
| 4375 | - if(isset($_mimePartObject->parameters['CHARSET'])) { |
|
| 5169 | + if(is_array($_mimePartObject->parameters)) |
|
| 5170 | + { |
|
| 5171 | + if(isset($_mimePartObject->parameters['CHARSET'])) |
|
| 5172 | + { |
|
| 4376 | 5173 | $charSet = $_mimePartObject->parameters['CHARSET']; |
| 4377 | 5174 | $CharsetFound=true; |
| 4378 | 5175 | } |
@@ -4393,7 +5190,10 @@ discard block |
||
| 4393 | 5190 | function decodeMimePart($_mimeMessage, $_encoding, $_charset = '') |
| 4394 | 5191 | { |
| 4395 | 5192 | // decode the part |
| 4396 | - if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true)); |
|
| 5193 | + if (self::$debug) |
|
| 5194 | + { |
|
| 5195 | + error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true)); |
|
| 5196 | + } |
|
| 4397 | 5197 | switch (strtoupper($_encoding)) |
| 4398 | 5198 | { |
| 4399 | 5199 | case 'BASE64': |
@@ -4434,13 +5234,19 @@ discard block |
||
| 4434 | 5234 | // sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that |
| 4435 | 5235 | // as attachment AND as abstracted ical information (we use our notification style here). |
| 4436 | 5236 | $partText = $partCalendar = $partHTML = null; |
| 4437 | - if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure)); |
|
| 5237 | + if (self::$debug) |
|
| 5238 | + { |
|
| 5239 | + _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure)); |
|
| 5240 | + } |
|
| 4438 | 5241 | //error_log(__METHOD__.' ('.__LINE__.') '); |
| 4439 | 5242 | $ignore_first_part = true; |
| 4440 | 5243 | foreach($_structure->contentTypeMap() as $mime_id => $mime_type) |
| 4441 | 5244 | { |
| 4442 | 5245 | //error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part); |
| 4443 | - if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>"; |
|
| 5246 | + if (self::$debug) |
|
| 5247 | + { |
|
| 5248 | + echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>"; |
|
| 5249 | + } |
|
| 4444 | 5250 | |
| 4445 | 5251 | if ($ignore_first_part) |
| 4446 | 5252 | { |
@@ -4456,15 +5262,24 @@ discard block |
||
| 4456 | 5262 | switch($mimePart->getSubType()) |
| 4457 | 5263 | { |
| 4458 | 5264 | case 'plain': |
| 4459 | - if ($mimePart->getBytes() > 0) $partText = $mimePart; |
|
| 5265 | + if ($mimePart->getBytes() > 0) |
|
| 5266 | + { |
|
| 5267 | + $partText = $mimePart; |
|
| 5268 | + } |
|
| 4460 | 5269 | break; |
| 4461 | 5270 | |
| 4462 | 5271 | case 'html': |
| 4463 | - if ($mimePart->getBytes() > 0) $partHTML = $mimePart; |
|
| 5272 | + if ($mimePart->getBytes() > 0) |
|
| 5273 | + { |
|
| 5274 | + $partHTML = $mimePart; |
|
| 5275 | + } |
|
| 4464 | 5276 | break; |
| 4465 | 5277 | |
| 4466 | 5278 | case 'calendar': |
| 4467 | - if ($mimePart->getBytes() > 0) $partCalendar = $mimePart; |
|
| 5279 | + if ($mimePart->getBytes() > 0) |
|
| 5280 | + { |
|
| 5281 | + $partCalendar = $mimePart; |
|
| 5282 | + } |
|
| 4468 | 5283 | break; |
| 4469 | 5284 | } |
| 4470 | 5285 | break; |
@@ -4477,7 +5292,10 @@ discard block |
||
| 4477 | 5292 | if (count($mimePart->getParts()) > 1) |
| 4478 | 5293 | { |
| 4479 | 5294 | // in a multipart alternative we treat the multipart/related as html part |
| 4480 | - if (self::$debug) error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts"); |
|
| 5295 | + if (self::$debug) |
|
| 5296 | + { |
|
| 5297 | + error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts"); |
|
| 5298 | + } |
|
| 4481 | 5299 | $partHTML = $mimePart; |
| 4482 | 5300 | break 3; // GET OUT OF LOOP, will be processed according to type |
| 4483 | 5301 | } |
@@ -4558,9 +5376,15 @@ discard block |
||
| 4558 | 5376 | */ |
| 4559 | 5377 | function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array()) |
| 4560 | 5378 | { |
| 4561 | - if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>"; |
|
| 5379 | + if (self::$debug) |
|
| 5380 | + { |
|
| 5381 | + echo __METHOD__."$_uid, $_htmlMode<br>"; |
|
| 5382 | + } |
|
| 4562 | 5383 | $bodyPart = array(); |
| 4563 | - if (self::$debug) _debug_array($_structure); |
|
| 5384 | + if (self::$debug) |
|
| 5385 | + { |
|
| 5386 | + _debug_array($_structure); |
|
| 5387 | + } |
|
| 4564 | 5388 | |
| 4565 | 5389 | $ignore_first_part = true; |
| 4566 | 5390 | //$skipParts = array(); |
@@ -4568,7 +5392,10 @@ discard block |
||
| 4568 | 5392 | foreach($_structure->contentTypeMap() as $mime_id => $mime_type) |
| 4569 | 5393 | { |
| 4570 | 5394 | //error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"); |
| 4571 | - if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>"; |
|
| 5395 | + if (self::$debug) |
|
| 5396 | + { |
|
| 5397 | + echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>"; |
|
| 5398 | + } |
|
| 4572 | 5399 | if ($ignore_first_part) |
| 4573 | 5400 | { |
| 4574 | 5401 | $ignore_first_part = false; |
@@ -4586,7 +5413,10 @@ discard block |
||
| 4586 | 5413 | switch($part->getPrimaryType()) |
| 4587 | 5414 | { |
| 4588 | 5415 | case 'multipart': |
| 4589 | - if ($part->getDisposition() == 'attachment') continue; |
|
| 5416 | + if ($part->getDisposition() == 'attachment') |
|
| 5417 | + { |
|
| 5418 | + continue; |
|
| 5419 | + } |
|
| 4590 | 5420 | switch($part->getSubType()) |
| 4591 | 5421 | { |
| 4592 | 5422 | case 'alternative': |
@@ -4651,7 +5481,9 @@ discard block |
||
| 4651 | 5481 | if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment') |
| 4652 | 5482 | { |
| 4653 | 5483 | $skipParts[$mime_id.'.0'] = $mime_type; |
| 4654 | - foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;} |
|
| 5484 | + foreach($part->contentTypeMap() as $sub_id => $sub_type) |
|
| 5485 | + { |
|
| 5486 | +$skipParts[$sub_id] = $sub_type;} |
|
| 4655 | 5487 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts)); |
| 4656 | 5488 | //break 2; |
| 4657 | 5489 | } |
@@ -4694,7 +5526,10 @@ discard block |
||
| 4694 | 5526 | */ |
| 4695 | 5527 | function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true) |
| 4696 | 5528 | { |
| 4697 | - if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)"); |
|
| 5529 | + if (self::$debug) |
|
| 5530 | + { |
|
| 5531 | + error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)"); |
|
| 5532 | + } |
|
| 4698 | 5533 | |
| 4699 | 5534 | if (empty($_folder)) |
| 4700 | 5535 | { |
@@ -4703,7 +5538,10 @@ discard block |
||
| 4703 | 5538 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']); |
| 4704 | 5539 | // querying contents of body part |
| 4705 | 5540 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 4706 | - if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid; |
|
| 5541 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 5542 | + { |
|
| 5543 | + $_uid = (array)$_uid; |
|
| 5544 | + } |
|
| 4707 | 5545 | $uidsToFetch->add($_uid); |
| 4708 | 5546 | |
| 4709 | 5547 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -4711,9 +5549,12 @@ discard block |
||
| 4711 | 5549 | 'peek' => $_preserveSeen, |
| 4712 | 5550 | 'decode' => true, // try decode on server, does NOT neccessary work |
| 4713 | 5551 | ); |
| 4714 | - if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder))) |
|
| 5552 | + if ($_tryDecodingServerside===false) |
|
| 5553 | + { |
|
| 5554 | + // || ($_tryDecodingServerside&&$this->isDraftFolder($_folder))) |
|
| 4715 | 5555 | { |
| 4716 | 5556 | $_tryDecodingServerside=false; |
| 5557 | + } |
|
| 4717 | 5558 | $fetchParams = array( |
| 4718 | 5559 | 'peek' => $_preserveSeen, |
| 4719 | 5560 | ); |
@@ -4755,7 +5596,10 @@ discard block |
||
| 4755 | 5596 | { |
| 4756 | 5597 | //error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace()); |
| 4757 | 5598 | $bodyPart = array(); |
| 4758 | - if (self::$debug) _debug_array(array($_structure,function_backtrace())); |
|
| 5599 | + if (self::$debug) |
|
| 5600 | + { |
|
| 5601 | + _debug_array(array($_structure,function_backtrace())); |
|
| 5602 | + } |
|
| 4759 | 5603 | |
| 4760 | 5604 | if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text'))) |
| 4761 | 5605 | { |
@@ -4806,8 +5650,12 @@ discard block |
||
| 4806 | 5650 | */ |
| 4807 | 5651 | function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '', &$calendar_part=null) |
| 4808 | 5652 | { |
| 4809 | - if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>"; |
|
| 4810 | - if($_htmlOptions != '') { |
|
| 5653 | + if (self::$debug) |
|
| 5654 | + { |
|
| 5655 | + echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>"; |
|
| 5656 | + } |
|
| 5657 | + if($_htmlOptions != '') |
|
| 5658 | + { |
|
| 4811 | 5659 | $this->htmlOptions = $_htmlOptions; |
| 4812 | 5660 | } |
| 4813 | 5661 | if (empty($_folder)) |
@@ -4896,7 +5744,9 @@ discard block |
||
| 4896 | 5744 | default: |
| 4897 | 5745 | $bodyPart = array($this->getTextPart($_uid, $_structure, $this->htmlOptions, $_preserveSeen)); |
| 4898 | 5746 | } |
| 4899 | - } else { |
|
| 5747 | + } |
|
| 5748 | + else |
|
| 5749 | + { |
|
| 4900 | 5750 | // what if the structure->disposition is attachment ,... |
| 4901 | 5751 | } |
| 4902 | 5752 | return self::normalizeBodyParts($bodyPart); |
@@ -4907,13 +5757,18 @@ discard block |
||
| 4907 | 5757 | { |
| 4908 | 5758 | case 'rfc822': |
| 4909 | 5759 | $newStructure = $_structure->getParts(); |
| 4910 | - if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);} |
|
| 5760 | + if (self::$debug) |
|
| 5761 | + { |
|
| 5762 | +echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);} |
|
| 4911 | 5763 | return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder)); |
| 4912 | 5764 | } |
| 4913 | 5765 | break; |
| 4914 | 5766 | |
| 4915 | 5767 | default: |
| 4916 | - if (self::$debug) _debug_array($_structure); |
|
| 5768 | + if (self::$debug) |
|
| 5769 | + { |
|
| 5770 | + _debug_array($_structure); |
|
| 5771 | + } |
|
| 4917 | 5772 | return array( |
| 4918 | 5773 | array( |
| 4919 | 5774 | 'body' => lang('The mimeparser can not parse this message.').$_structure->getType(), |
@@ -4937,9 +5792,12 @@ discard block |
||
| 4937 | 5792 | { |
| 4938 | 5793 | foreach($_bodyParts as $singleBodyPart) |
| 4939 | 5794 | { |
| 4940 | - if (!isset($singleBodyPart['body'])) { |
|
| 5795 | + if (!isset($singleBodyPart['body'])) |
|
| 5796 | + { |
|
| 4941 | 5797 | $buff = self::normalizeBodyParts($singleBodyPart); |
| 4942 | - foreach ((array)$buff as $val) { $body2return[] = $val;} |
|
| 5798 | + foreach ((array)$buff as $val) |
|
| 5799 | + { |
|
| 5800 | +$body2return[] = $val;} |
|
| 4943 | 5801 | continue; |
| 4944 | 5802 | } |
| 4945 | 5803 | $body2return[] = $singleBodyPart; |
@@ -4965,13 +5823,20 @@ discard block |
||
| 4965 | 5823 | $message=''; |
| 4966 | 5824 | for($i=0; $i<count($bodyParts); $i++) |
| 4967 | 5825 | { |
| 4968 | - if (!isset($bodyParts[$i]['body'])) { |
|
| 5826 | + if (!isset($bodyParts[$i]['body'])) |
|
| 5827 | + { |
|
| 4969 | 5828 | $bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy); |
| 4970 | 5829 | $message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body']; |
| 4971 | 5830 | continue; |
| 4972 | 5831 | } |
| 4973 | - if (isset($bodyParts[$i]['error'])) continue; |
|
| 4974 | - if (empty($bodyParts[$i]['body'])) continue; |
|
| 5832 | + if (isset($bodyParts[$i]['error'])) |
|
| 5833 | + { |
|
| 5834 | + continue; |
|
| 5835 | + } |
|
| 5836 | + if (empty($bodyParts[$i]['body'])) |
|
| 5837 | + { |
|
| 5838 | + continue; |
|
| 5839 | + } |
|
| 4975 | 5840 | // some characterreplacements, as they fail to translate |
| 4976 | 5841 | $sar = array( |
| 4977 | 5842 | '@(\x84|\x93|\x94)@', |
@@ -4998,13 +5863,17 @@ discard block |
||
| 4998 | 5863 | $bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']); |
| 4999 | 5864 | } |
| 5000 | 5865 | |
| 5001 | - if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']); |
|
| 5866 | + if ($bodyParts[$i]['charSet']===false) |
|
| 5867 | + { |
|
| 5868 | + $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']); |
|
| 5869 | + } |
|
| 5002 | 5870 | // add line breaks to $bodyParts |
| 5003 | 5871 | //error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']); |
| 5004 | 5872 | $newBody = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']); |
| 5005 | 5873 | //error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody); |
| 5006 | 5874 | $mailClass->activeMimeType = 'text/plain'; |
| 5007 | - if ($bodyParts[$i]['mimeType'] == 'text/html') { |
|
| 5875 | + if ($bodyParts[$i]['mimeType'] == 'text/html') |
|
| 5876 | + { |
|
| 5008 | 5877 | $mailClass->activeMimeType = $bodyParts[$i]['mimeType']; |
| 5009 | 5878 | if (!$preserveHTML) |
| 5010 | 5879 | { |
@@ -5050,15 +5919,28 @@ discard block |
||
| 5050 | 5919 | // as we switched off HTMLaweds tidy functionality |
| 5051 | 5920 | $newBody = str_replace(array('&amp;','<DIV><BR></DIV>',"<DIV> </DIV>",'<div> </div>'),array('&','<BR>','<BR>','<BR>'),$newBody); |
| 5052 | 5921 | $newBody = $htmLawed->run($newBody,self::$htmLawed_config); |
| 5053 | - if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3]; |
|
| 5922 | + if ($hasOther && $preserveHTML) |
|
| 5923 | + { |
|
| 5924 | + $newBody = $matches[1]. $newBody. $matches[3]; |
|
| 5925 | + } |
|
| 5054 | 5926 | $alreadyHtmlLawed=true; |
| 5055 | 5927 | } |
| 5056 | 5928 | //error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody); |
| 5057 | - if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true); |
|
| 5929 | + if ($preserveHTML==false) |
|
| 5930 | + { |
|
| 5931 | + $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true); |
|
| 5932 | + } |
|
| 5058 | 5933 | //error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody); |
| 5059 | - if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n |
|
| 5934 | + if ($preserveHTML==false) |
|
| 5935 | + { |
|
| 5936 | + $newBody = nl2br($newBody); |
|
| 5937 | + } |
|
| 5938 | + // we need this, as htmLawed removes \r\n |
|
| 5060 | 5939 | /*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted |
| 5061 | - if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody); |
|
| 5940 | + if ($preserveHTML==false) |
|
| 5941 | + { |
|
| 5942 | + $newBody = str_replace("<br />","\r\n",$newBody); |
|
| 5943 | + } |
|
| 5062 | 5944 | //error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody); |
| 5063 | 5945 | } |
| 5064 | 5946 | $message .= $newBody; |
@@ -5095,12 +5977,12 @@ discard block |
||
| 5095 | 5977 | substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith |
| 5096 | 5978 | ) |
| 5097 | 5979 | ) |
| 5098 | - ) |
|
| 5099 | - { |
|
| 5980 | + ) { |
|
| 5100 | 5981 | $s=explode(" ", $line); |
| 5101 | 5982 | $line = ""; |
| 5102 | 5983 | $linecnt = 0; |
| 5103 | - foreach ($s as &$v) { |
|
| 5984 | + foreach ($s as &$v) |
|
| 5985 | + { |
|
| 5104 | 5986 | $cnt = strlen($v); |
| 5105 | 5987 | // only break long words within the wordboundaries, |
| 5106 | 5988 | // but it may destroy links, so we check for href and dont do it if we find one |
@@ -5110,14 +5992,20 @@ discard block |
||
| 5110 | 5992 | $v=wordwrap($v, $allowedLength, $cut, true); |
| 5111 | 5993 | } |
| 5112 | 5994 | // the rest should be broken at the start of the new word that exceeds the limit |
| 5113 | - if ($linecnt+$cnt > $allowedLength) { |
|
| 5995 | + if ($linecnt+$cnt > $allowedLength) |
|
| 5996 | + { |
|
| 5114 | 5997 | $v=$cut.$v; |
| 5115 | 5998 | #$linecnt = 0; |
| 5116 | 5999 | $linecnt =strlen($v)-strlen($cut); |
| 5117 | - } else { |
|
| 6000 | + } |
|
| 6001 | + else |
|
| 6002 | + { |
|
| 5118 | 6003 | $linecnt += $cnt; |
| 5119 | 6004 | } |
| 5120 | - if (strlen($v)) $line .= (strlen($line) ? " " : "").$v; |
|
| 6005 | + if (strlen($v)) |
|
| 6006 | + { |
|
| 6007 | + $line .= (strlen($line) ? " " : "").$v; |
|
| 6008 | + } |
|
| 5121 | 6009 | } |
| 5122 | 6010 | } |
| 5123 | 6011 | $newStr .= $line . "\n"; |
@@ -5138,11 +6026,18 @@ discard block |
||
| 5138 | 6026 | function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false) |
| 5139 | 6027 | { |
| 5140 | 6028 | //error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace()); |
| 5141 | - if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6029 | + if (empty($_folder)) |
|
| 6030 | + { |
|
| 6031 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6032 | + } |
|
| 5142 | 6033 | //error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder"); |
| 5143 | - if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) { |
|
| 6034 | + if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) |
|
| 6035 | + { |
|
| 5144 | 6036 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5145 | - if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid; |
|
| 6037 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6038 | + { |
|
| 6039 | + $_uid = (array)$_uid; |
|
| 6040 | + } |
|
| 5146 | 6041 | $uidsToFetch->add($_uid); |
| 5147 | 6042 | |
| 5148 | 6043 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -5152,8 +6047,10 @@ discard block |
||
| 5152 | 6047 | $headersNew = $this->icServer->fetch($_folder, $fquery, array( |
| 5153 | 6048 | 'ids' => $uidsToFetch, |
| 5154 | 6049 | )); |
| 5155 | - if (is_object($headersNew)) { |
|
| 5156 | - foreach($headersNew as &$_headerObject) { |
|
| 6050 | + if (is_object($headersNew)) |
|
| 6051 | + { |
|
| 6052 | + foreach($headersNew as &$_headerObject) |
|
| 6053 | + { |
|
| 5157 | 6054 | $env = $_headerObject->getEnvelope(); |
| 5158 | 6055 | //_debug_array($envFields->singleFields()); |
| 5159 | 6056 | $singleFields = $envFields->singleFields(); |
@@ -5170,7 +6067,10 @@ discard block |
||
| 5170 | 6067 | //error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses)); |
| 5171 | 6068 | $envelope[$v]=$env->$v->addresses; |
| 5172 | 6069 | $address = array(); |
| 5173 | - if (!is_array($envelope[$v])) break; |
|
| 6070 | + if (!is_array($envelope[$v])) |
|
| 6071 | + { |
|
| 6072 | + break; |
|
| 6073 | + } |
|
| 5174 | 6074 | foreach ($envelope[$v] as $k => $ad) |
| 5175 | 6075 | { |
| 5176 | 6076 | if (stripos($ad,'@')===false) |
@@ -5207,7 +6107,9 @@ discard block |
||
| 5207 | 6107 | } |
| 5208 | 6108 | } |
| 5209 | 6109 | return $envelope; |
| 5210 | - } else { |
|
| 6110 | + } |
|
| 6111 | + else |
|
| 6112 | + { |
|
| 5211 | 6113 | |
| 5212 | 6114 | $headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder); |
| 5213 | 6115 | |
@@ -5218,19 +6120,43 @@ discard block |
||
| 5218 | 6120 | 'SUBJECT' => ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']), |
| 5219 | 6121 | 'MESSAGE_ID' => $headers['MESSAGE-ID'] |
| 5220 | 6122 | ); |
| 5221 | - if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO']; |
|
| 5222 | - if (isset($headers['REFERENCES'])) $newData['REFERENCES'] = $headers['REFERENCES']; |
|
| 5223 | - if (isset($headers['THREAD-TOPIC'])) $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC']; |
|
| 5224 | - if (isset($headers['THREAD-INDEX'])) $newData['THREAD-INDEX'] = $headers['THREAD-INDEX']; |
|
| 5225 | - if (isset($headers['LIST-ID'])) $newData['LIST-ID'] = $headers['LIST-ID']; |
|
| 5226 | - if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE']; |
|
| 6123 | + if (isset($headers['IN-REPLY-TO'])) |
|
| 6124 | + { |
|
| 6125 | + $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO']; |
|
| 6126 | + } |
|
| 6127 | + if (isset($headers['REFERENCES'])) |
|
| 6128 | + { |
|
| 6129 | + $newData['REFERENCES'] = $headers['REFERENCES']; |
|
| 6130 | + } |
|
| 6131 | + if (isset($headers['THREAD-TOPIC'])) |
|
| 6132 | + { |
|
| 6133 | + $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC']; |
|
| 6134 | + } |
|
| 6135 | + if (isset($headers['THREAD-INDEX'])) |
|
| 6136 | + { |
|
| 6137 | + $newData['THREAD-INDEX'] = $headers['THREAD-INDEX']; |
|
| 6138 | + } |
|
| 6139 | + if (isset($headers['LIST-ID'])) |
|
| 6140 | + { |
|
| 6141 | + $newData['LIST-ID'] = $headers['LIST-ID']; |
|
| 6142 | + } |
|
| 6143 | + if (isset($headers['SIZE'])) |
|
| 6144 | + { |
|
| 6145 | + $newData['SIZE'] = $headers['SIZE']; |
|
| 6146 | + } |
|
| 5227 | 6147 | //_debug_array($newData); |
| 5228 | 6148 | $recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'); |
| 5229 | - foreach($recepientList as $recepientType) { |
|
| 5230 | - if(isset($headers[$recepientType])) { |
|
| 5231 | - if ($decode) $headers[$recepientType] = self::decode_header($headers[$recepientType],true); |
|
| 6149 | + foreach($recepientList as $recepientType) |
|
| 6150 | + { |
|
| 6151 | + if(isset($headers[$recepientType])) |
|
| 6152 | + { |
|
| 6153 | + if ($decode) |
|
| 6154 | + { |
|
| 6155 | + $headers[$recepientType] = self::decode_header($headers[$recepientType],true); |
|
| 6156 | + } |
|
| 5232 | 6157 | //error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType])); |
| 5233 | - foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) { |
|
| 6158 | + foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) |
|
| 6159 | + { |
|
| 5234 | 6160 | $addressData = array( |
| 5235 | 6161 | 'PERSONAL_NAME' => $singleAddress->personal ? $singleAddress->personal : 'NIL', |
| 5236 | 6162 | 'AT_DOMAIN_LIST' => $singleAddress->adl ? $singleAddress->adl : 'NIL', |
@@ -5238,17 +6164,25 @@ discard block |
||
| 5238 | 6164 | 'HOST_NAME' => $singleAddress->host ? $singleAddress->host : 'NIL', |
| 5239 | 6165 | 'EMAIL' => $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox, |
| 5240 | 6166 | ); |
| 5241 | - if($addressData['PERSONAL_NAME'] != 'NIL') { |
|
| 6167 | + if($addressData['PERSONAL_NAME'] != 'NIL') |
|
| 6168 | + { |
|
| 5242 | 6169 | $addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal); |
| 5243 | - } else { |
|
| 6170 | + } |
|
| 6171 | + else |
|
| 6172 | + { |
|
| 5244 | 6173 | $addressData['RFC822_EMAIL'] = 'NIL'; |
| 5245 | 6174 | } |
| 5246 | 6175 | $newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData; |
| 5247 | 6176 | } |
| 5248 | - } else { |
|
| 5249 | - if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') { |
|
| 6177 | + } |
|
| 6178 | + else |
|
| 6179 | + { |
|
| 6180 | + if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') |
|
| 6181 | + { |
|
| 5250 | 6182 | $newData[$recepientType] = $newData['FROM']; |
| 5251 | - } else { |
|
| 6183 | + } |
|
| 6184 | + else |
|
| 6185 | + { |
|
| 5252 | 6186 | $newData[$recepientType] = array(); |
| 5253 | 6187 | } |
| 5254 | 6188 | } |
@@ -5271,9 +6205,15 @@ discard block |
||
| 5271 | 6205 | function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='') |
| 5272 | 6206 | { |
| 5273 | 6207 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder); |
| 5274 | - if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6208 | + if (empty($_folder)) |
|
| 6209 | + { |
|
| 6210 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6211 | + } |
|
| 5275 | 6212 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5276 | - if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid; |
|
| 6213 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6214 | + { |
|
| 6215 | + $_uid = (array)$_uid; |
|
| 6216 | + } |
|
| 5277 | 6217 | $uidsToFetch->add($_uid); |
| 5278 | 6218 | |
| 5279 | 6219 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -5291,7 +6231,8 @@ discard block |
||
| 5291 | 6231 | $headersNew = $this->icServer->fetch($_folder, $fquery, array( |
| 5292 | 6232 | 'ids' => $uidsToFetch, |
| 5293 | 6233 | )); |
| 5294 | - if (is_object($headersNew)) { |
|
| 6234 | + if (is_object($headersNew)) |
|
| 6235 | + { |
|
| 5295 | 6236 | foreach($headersNew as $_fetchObject) |
| 5296 | 6237 | { |
| 5297 | 6238 | $headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE); |
@@ -5313,11 +6254,17 @@ discard block |
||
| 5313 | 6254 | } |
| 5314 | 6255 | if ($decode === 'object') |
| 5315 | 6256 | { |
| 5316 | - if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']); |
|
| 6257 | + if (is_object($headers)) |
|
| 6258 | + { |
|
| 6259 | + $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']); |
|
| 6260 | + } |
|
| 5317 | 6261 | return $headers; |
| 5318 | 6262 | } |
| 5319 | 6263 | $retValue = is_object($headers) ? $headers->toArray():array(); |
| 5320 | - if ($size) $retValue['size'] = $size; |
|
| 6264 | + if ($size) |
|
| 6265 | + { |
|
| 6266 | + $retValue['size'] = $size; |
|
| 6267 | + } |
|
| 5321 | 6268 | } |
| 5322 | 6269 | $retValue = array_change_key_case($retValue,CASE_UPPER); |
| 5323 | 6270 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue)); |
@@ -5349,10 +6296,16 @@ discard block |
||
| 5349 | 6296 | function getMessageRawHeader($_uid, $_partID = '', $_folder = '') |
| 5350 | 6297 | { |
| 5351 | 6298 | static $rawHeaders; |
| 5352 | - if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6299 | + if (empty($_folder)) |
|
| 6300 | + { |
|
| 6301 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6302 | + } |
|
| 5353 | 6303 | //error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder"); |
| 5354 | 6304 | |
| 5355 | - 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); |
|
| 6305 | + if (is_null($rawHeaders)||!is_array($rawHeaders)) |
|
| 6306 | + { |
|
| 6307 | + $rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1); |
|
| 6308 | + } |
|
| 5356 | 6309 | if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)])) |
| 5357 | 6310 | { |
| 5358 | 6311 | //error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder"); |
@@ -5360,7 +6313,10 @@ discard block |
||
| 5360 | 6313 | } |
| 5361 | 6314 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5362 | 6315 | $uid = $_uid; |
| 5363 | - if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid; |
|
| 6316 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6317 | + { |
|
| 6318 | + $uid = (array)$_uid; |
|
| 6319 | + } |
|
| 5364 | 6320 | $uidsToFetch->add($uid); |
| 5365 | 6321 | |
| 5366 | 6322 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -5376,8 +6332,10 @@ discard block |
||
| 5376 | 6332 | $headersNew = $this->icServer->fetch($_folder, $fquery, array( |
| 5377 | 6333 | 'ids' => $uidsToFetch, |
| 5378 | 6334 | )); |
| 5379 | - if (is_object($headersNew)) { |
|
| 5380 | - foreach($headersNew as &$_headerObject) { |
|
| 6335 | + if (is_object($headersNew)) |
|
| 6336 | + { |
|
| 6337 | + foreach($headersNew as &$_headerObject) |
|
| 6338 | + { |
|
| 5381 | 6339 | $retValue = $_headerObject->getHeaderText(); |
| 5382 | 6340 | if ($_partID != '') |
| 5383 | 6341 | { |
@@ -5405,22 +6363,33 @@ discard block |
||
| 5405 | 6363 | static function &getStyles($_bodyParts) |
| 5406 | 6364 | { |
| 5407 | 6365 | $style = ''; |
| 5408 | - if (empty($_bodyParts)) return ""; |
|
| 5409 | - foreach((array)$_bodyParts as $singleBodyPart) { |
|
| 5410 | - if (!isset($singleBodyPart['body'])) { |
|
| 6366 | + if (empty($_bodyParts)) |
|
| 6367 | + { |
|
| 6368 | + return ""; |
|
| 6369 | + } |
|
| 6370 | + foreach((array)$_bodyParts as $singleBodyPart) |
|
| 6371 | + { |
|
| 6372 | + if (!isset($singleBodyPart['body'])) |
|
| 6373 | + { |
|
| 5411 | 6374 | $singleBodyPart['body'] = self::getStyles($singleBodyPart); |
| 5412 | 6375 | $style .= $singleBodyPart['body']; |
| 5413 | 6376 | continue; |
| 5414 | 6377 | } |
| 5415 | 6378 | |
| 5416 | - if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']); |
|
| 6379 | + if ($singleBodyPart['charSet']===false) |
|
| 6380 | + { |
|
| 6381 | + $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']); |
|
| 6382 | + } |
|
| 5417 | 6383 | $singleBodyPart['body'] = Translation::convert( |
| 5418 | 6384 | $singleBodyPart['body'], |
| 5419 | 6385 | strtolower($singleBodyPart['charSet']) |
| 5420 | 6386 | ); |
| 5421 | 6387 | $ct = 0; |
| 5422 | 6388 | $newStyle=array(); |
| 5423 | - if (stripos($singleBodyPart['body'],'<style')!==false) $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle); |
|
| 6389 | + if (stripos($singleBodyPart['body'],'<style')!==false) |
|
| 6390 | + { |
|
| 6391 | + $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle); |
|
| 6392 | + } |
|
| 5424 | 6393 | if ($ct>0) |
| 5425 | 6394 | { |
| 5426 | 6395 | //error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle)); |
@@ -5452,7 +6421,11 @@ discard block |
||
| 5452 | 6421 | // CSS Security |
| 5453 | 6422 | // http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets |
| 5454 | 6423 | $css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style); |
| 5455 | - if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included |
|
| 6424 | + if (stripos($css,'script')!==false) |
|
| 6425 | + { |
|
| 6426 | + Mail\Html::replaceTagsCompletley($css,'script'); |
|
| 6427 | + } |
|
| 6428 | + // Strip out script that may be included |
|
| 5456 | 6429 | // 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 |
| 5457 | 6430 | // as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it |
| 5458 | 6431 | $css = str_replace(array(':','<!--','-->'),array(': ','',''),$css); |
@@ -5474,8 +6447,14 @@ discard block |
||
| 5474 | 6447 | { |
| 5475 | 6448 | //TODO: caching einbauen static! |
| 5476 | 6449 | static $rawBody; |
| 5477 | - if (is_null($rawBody)) $rawBody = array(); |
|
| 5478 | - if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6450 | + if (is_null($rawBody)) |
|
| 6451 | + { |
|
| 6452 | + $rawBody = array(); |
|
| 6453 | + } |
|
| 6454 | + if (empty($_folder)) |
|
| 6455 | + { |
|
| 6456 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6457 | + } |
|
| 5479 | 6458 | if (!$_stream && isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)])) |
| 5480 | 6459 | { |
| 5481 | 6460 | //error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder"); |
@@ -5484,7 +6463,10 @@ discard block |
||
| 5484 | 6463 | |
| 5485 | 6464 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5486 | 6465 | $uid = $_uid; |
| 5487 | - if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid; |
|
| 6466 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6467 | + { |
|
| 6468 | + $uid = (array)$_uid; |
|
| 6469 | + } |
|
| 5488 | 6470 | $uidsToFetch->add($uid); |
| 5489 | 6471 | |
| 5490 | 6472 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -5497,8 +6479,10 @@ discard block |
||
| 5497 | 6479 | $headersNew = $this->icServer->fetch($_folder, $fquery, array( |
| 5498 | 6480 | 'ids' => $uidsToFetch, |
| 5499 | 6481 | )); |
| 5500 | - if (is_object($headersNew)) { |
|
| 5501 | - foreach($headersNew as &$_headerObject) { |
|
| 6482 | + if (is_object($headersNew)) |
|
| 6483 | + { |
|
| 6484 | + foreach($headersNew as &$_headerObject) |
|
| 6485 | + { |
|
| 5502 | 6486 | $body = $_headerObject->getFullMsg($_stream); |
| 5503 | 6487 | if ($_partID != '') |
| 5504 | 6488 | { |
@@ -5534,14 +6518,20 @@ discard block |
||
| 5534 | 6518 | */ |
| 5535 | 6519 | function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false) |
| 5536 | 6520 | { |
| 5537 | - if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID"); |
|
| 6521 | + if (self::$debug) |
|
| 6522 | + { |
|
| 6523 | + error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID"); |
|
| 6524 | + } |
|
| 5538 | 6525 | |
| 5539 | 6526 | if (empty($_folder)) |
| 5540 | 6527 | { |
| 5541 | 6528 | $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
| 5542 | 6529 | } |
| 5543 | 6530 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5544 | - if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid; |
|
| 6531 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6532 | + { |
|
| 6533 | + $_uid = (array)$_uid; |
|
| 6534 | + } |
|
| 5545 | 6535 | $uidsToFetch->add($_uid); |
| 5546 | 6536 | try |
| 5547 | 6537 | { |
@@ -5550,7 +6540,10 @@ discard block |
||
| 5550 | 6540 | // $fquery->envelope(); |
| 5551 | 6541 | // $fquery->size(); |
| 5552 | 6542 | $_fquery->structure(); |
| 5553 | - if ($_partID) $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen)); |
|
| 6543 | + if ($_partID) |
|
| 6544 | + { |
|
| 6545 | + $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen)); |
|
| 6546 | + } |
|
| 5554 | 6547 | |
| 5555 | 6548 | $mail = $this->icServer->fetch($_folder, $_fquery, array( |
| 5556 | 6549 | 'ids' => $uidsToFetch, |
@@ -5581,16 +6574,28 @@ discard block |
||
| 5581 | 6574 | */ |
| 5582 | 6575 | function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='') |
| 5583 | 6576 | { |
| 5584 | - if (self::$debug) error_log( __METHOD__.":$_uid, $_partID"); |
|
| 5585 | - if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6577 | + if (self::$debug) |
|
| 6578 | + { |
|
| 6579 | + error_log( __METHOD__.":$_uid, $_partID"); |
|
| 6580 | + } |
|
| 6581 | + if (empty($_folder)) |
|
| 6582 | + { |
|
| 6583 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6584 | + } |
|
| 5586 | 6585 | $attachments = array(); |
| 5587 | 6586 | if (!isset($_structure)) |
| 5588 | 6587 | { |
| 5589 | 6588 | $_structure = $this->getStructure($_uid, $_partID,$_folder,true); |
| 5590 | 6589 | //error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true)); |
| 5591 | 6590 | } |
| 5592 | - if (!$_structure || !$_structure->contentTypeMap()) return array(); |
|
| 5593 | - if (!empty($_partID)) $_structure = $_structure->getPart($_partID); |
|
| 6591 | + if (!$_structure || !$_structure->contentTypeMap()) |
|
| 6592 | + { |
|
| 6593 | + return array(); |
|
| 6594 | + } |
|
| 6595 | + if (!empty($_partID)) |
|
| 6596 | + { |
|
| 6597 | + $_structure = $_structure->getPart($_partID); |
|
| 6598 | + } |
|
| 5594 | 6599 | $skipParts = array(); |
| 5595 | 6600 | $tnefParts = array(); |
| 5596 | 6601 | $skip = 0; |
@@ -5619,7 +6624,13 @@ discard block |
||
| 5619 | 6624 | if ($mime_type=='message/rfc822' && $_partID!=$mime_id) |
| 5620 | 6625 | { |
| 5621 | 6626 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap())); |
| 5622 | - foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;} |
|
| 6627 | + foreach($part->contentTypeMap() as $sub_id => $sub_type) |
|
| 6628 | + { |
|
| 6629 | +if ($sub_id != $mime_id) |
|
| 6630 | + { |
|
| 6631 | + $skipParts[$sub_id] = $sub_type; |
|
| 6632 | + } |
|
| 6633 | + } |
|
| 5623 | 6634 | } |
| 5624 | 6635 | if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text') |
| 5625 | 6636 | { |
@@ -5630,7 +6641,10 @@ discard block |
||
| 5630 | 6641 | $partDisposition='attachment'; |
| 5631 | 6642 | } |
| 5632 | 6643 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts)); |
| 5633 | - if (array_key_exists($mime_id,$skipParts)) continue; |
|
| 6644 | + if (array_key_exists($mime_id,$skipParts)) |
|
| 6645 | + { |
|
| 6646 | + continue; |
|
| 6647 | + } |
|
| 5634 | 6648 | |
| 5635 | 6649 | if ($partDisposition == 'attachment' || |
| 5636 | 6650 | (($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') || |
@@ -5641,23 +6655,41 @@ discard block |
||
| 5641 | 6655 | { |
| 5642 | 6656 | // if type is message/rfc822 and _partID is given, and MimeID equals partID |
| 5643 | 6657 | // we attempt to fetch "ourselves" |
| 5644 | - if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue; |
|
| 6658 | + if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') |
|
| 6659 | + { |
|
| 6660 | + continue; |
|
| 6661 | + } |
|
| 5645 | 6662 | $attachment = $part->getAllDispositionParameters(); |
| 5646 | 6663 | $attachment['disposition'] = $part->getDisposition(); |
| 5647 | 6664 | $attachment['mimeType'] = $mime_type; |
| 5648 | 6665 | $attachment['uid'] = $_uid; |
| 5649 | 6666 | $attachment['partID'] = $mime_id; |
| 5650 | - if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName(); |
|
| 6667 | + if (!isset($attachment['name'])||empty($attachment['name'])) |
|
| 6668 | + { |
|
| 6669 | + $attachment['name'] = $part->getName(); |
|
| 6670 | + } |
|
| 5651 | 6671 | if ($fetchTextCalendar) |
| 5652 | 6672 | { |
| 5653 | 6673 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters())); |
| 5654 | 6674 | $method = $part->getContentTypeParameter('method'); |
| 5655 | - if ($method) $attachment['method'] = $method; |
|
| 5656 | - if (!isset($attachment['name'])) $attachment['name'] = 'event.ics'; |
|
| 6675 | + if ($method) |
|
| 6676 | + { |
|
| 6677 | + $attachment['method'] = $method; |
|
| 6678 | + } |
|
| 6679 | + if (!isset($attachment['name'])) |
|
| 6680 | + { |
|
| 6681 | + $attachment['name'] = 'event.ics'; |
|
| 6682 | + } |
|
| 5657 | 6683 | } |
| 5658 | 6684 | $attachment['size'] = $part->getBytes(); |
| 5659 | - if (($cid = $part->getContentId())) $attachment['cid'] = $cid; |
|
| 5660 | - 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); |
|
| 6685 | + if (($cid = $part->getContentId())) |
|
| 6686 | + { |
|
| 6687 | + $attachment['cid'] = $cid; |
|
| 6688 | + } |
|
| 6689 | + if (empty($attachment['name'])) |
|
| 6690 | + { |
|
| 6691 | + $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type); |
|
| 6692 | + } |
|
| 5661 | 6693 | //error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment)); |
| 5662 | 6694 | //typical winmail.dat attachment is |
| 5663 | 6695 | //Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat) |
@@ -5693,14 +6725,26 @@ discard block |
||
| 5693 | 6725 | $attachment['uid'] = $tnp['uid']; |
| 5694 | 6726 | $attachment['partID'] = $tnp['partID']; |
| 5695 | 6727 | $attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id; |
| 5696 | - if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName(); |
|
| 6728 | + if (!isset($attachment['name'])||empty($attachment['name'])) |
|
| 6729 | + { |
|
| 6730 | + $attachment['name'] = $part->getName(); |
|
| 6731 | + } |
|
| 5697 | 6732 | $attachment['size'] = $part->getBytes(); |
| 5698 | - if (($cid = $part->getContentId())) $attachment['cid'] = $cid; |
|
| 5699 | - 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']); |
|
| 6733 | + if (($cid = $part->getContentId())) |
|
| 6734 | + { |
|
| 6735 | + $attachment['cid'] = $cid; |
|
| 6736 | + } |
|
| 6737 | + if (empty($attachment['name'])) |
|
| 6738 | + { |
|
| 6739 | + $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']); |
|
| 6740 | + } |
|
| 5700 | 6741 | $attachments[] = $attachment; |
| 5701 | 6742 | } |
| 5702 | 6743 | } |
| 5703 | - if ($tnefResolved===false) $attachments[]=$tnp; |
|
| 6744 | + if ($tnefResolved===false) |
|
| 6745 | + { |
|
| 6746 | + $attachments[]=$tnp; |
|
| 6747 | + } |
|
| 5704 | 6748 | } |
| 5705 | 6749 | } |
| 5706 | 6750 | //error_log(__METHOD__.__LINE__.array2string($attachments)); |
@@ -5804,8 +6848,14 @@ discard block |
||
| 5804 | 6848 | |
| 5805 | 6849 | $attachment = $part->getAllDispositionParameters(); |
| 5806 | 6850 | $attachment['mimeType'] = $part->getType(); |
| 5807 | - if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName(); |
|
| 5808 | - if (($cid = $part->getContentId())) $attachment['cid'] = $cid; |
|
| 6851 | + if (!isset($attachment['filename'])||empty($attachment['filename'])) |
|
| 6852 | + { |
|
| 6853 | + $attachment['filename'] = $part->getName(); |
|
| 6854 | + } |
|
| 6855 | + if (($cid = $part->getContentId())) |
|
| 6856 | + { |
|
| 6857 | + $attachment['cid'] = $cid; |
|
| 6858 | + } |
|
| 5809 | 6859 | if (empty($attachment['filename'])) |
| 5810 | 6860 | { |
| 5811 | 6861 | $attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])? |
@@ -5817,7 +6867,10 @@ discard block |
||
| 5817 | 6867 | $attachments[$_uid.'@'.$_partID.'@'.$mime_id] = $attachment; |
| 5818 | 6868 | } |
| 5819 | 6869 | } |
| 5820 | - if (!is_array($attachments)) return false; |
|
| 6870 | + if (!is_array($attachments)) |
|
| 6871 | + { |
|
| 6872 | + return false; |
|
| 6873 | + } |
|
| 5821 | 6874 | return $attachments; |
| 5822 | 6875 | } |
| 5823 | 6876 | |
@@ -5836,10 +6889,16 @@ discard block |
||
| 5836 | 6889 | function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null) |
| 5837 | 6890 | { |
| 5838 | 6891 | //error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace()); |
| 5839 | - if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6892 | + if (!isset($_folder)) |
|
| 6893 | + { |
|
| 6894 | + $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox()); |
|
| 6895 | + } |
|
| 5840 | 6896 | |
| 5841 | 6897 | $uidsToFetch = new Horde_Imap_Client_Ids(); |
| 5842 | - if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid; |
|
| 6898 | + if (!(is_object($_uid) || is_array($_uid))) |
|
| 6899 | + { |
|
| 6900 | + $_uid = (array)$_uid; |
|
| 6901 | + } |
|
| 5843 | 6902 | $uidsToFetch->add($_uid); |
| 5844 | 6903 | |
| 5845 | 6904 | $fquery = new Horde_Imap_Client_Fetch_Query(); |
@@ -5848,8 +6907,10 @@ discard block |
||
| 5848 | 6907 | $headersNew = $this->icServer->fetch($_folder, $fquery, array( |
| 5849 | 6908 | 'ids' => $uidsToFetch, |
| 5850 | 6909 | )); |
| 5851 | - if (is_object($headersNew)) { |
|
| 5852 | - foreach($headersNew as $id=>$_headerObject) { |
|
| 6910 | + if (is_object($headersNew)) |
|
| 6911 | + { |
|
| 6912 | + foreach($headersNew as $id=>$_headerObject) |
|
| 6913 | + { |
|
| 5853 | 6914 | $body = $_headerObject->getFullMsg(); |
| 5854 | 6915 | if ($_partID != '') |
| 5855 | 6916 | { |
@@ -5863,7 +6924,10 @@ discard block |
||
| 5863 | 6924 | } |
| 5864 | 6925 | // if $partDisposition is empty, we assume attachment, and hope that the function |
| 5865 | 6926 | // itself is only triggered to fetch attachments |
| 5866 | - if (empty($partDisposition)) $partDisposition='attachment'; |
|
| 6927 | + if (empty($partDisposition)) |
|
| 6928 | + { |
|
| 6929 | + $partDisposition='attachment'; |
|
| 6930 | + } |
|
| 5867 | 6931 | if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar'))) |
| 5868 | 6932 | { |
| 5869 | 6933 | //$headerObject=$part->getAllDispositionParameters();//not used anywhere around here |
@@ -5872,13 +6936,19 @@ discard block |
||
| 5872 | 6936 | $charset = $part->getContentTypeParameter('charset'); |
| 5873 | 6937 | //$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" ); |
| 5874 | 6938 | $this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime); |
| 5875 | - if ($_returnPart) return $part; |
|
| 6939 | + if ($_returnPart) |
|
| 6940 | + { |
|
| 6941 | + return $part; |
|
| 6942 | + } |
|
| 5876 | 6943 | } |
| 5877 | 6944 | } |
| 5878 | 6945 | } |
| 5879 | 6946 | } |
| 5880 | 6947 | $ext = MimeMagic::mime2ext($structure_mime); |
| 5881 | - if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext; |
|
| 6948 | + if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) |
|
| 6949 | + { |
|
| 6950 | + $filename = trim($filename).'.'.$ext; |
|
| 6951 | + } |
|
| 5882 | 6952 | if (!$part) |
| 5883 | 6953 | { |
| 5884 | 6954 | throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder"); |
@@ -5894,7 +6964,10 @@ discard block |
||
| 5894 | 6964 | ); |
| 5895 | 6965 | |
| 5896 | 6966 | // try guessing the mimetype, if we get the application/octet-stream |
| 5897 | - if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']); |
|
| 6967 | + if (strtolower($attachmentData['type']) == 'application/octet-stream') |
|
| 6968 | + { |
|
| 6969 | + $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']); |
|
| 6970 | + } |
|
| 5898 | 6971 | # if the attachment holds a winmail number and is a winmail.dat then we have to handle that. |
| 5899 | 6972 | if ( $filename == 'winmail.dat' && $_winmail_nr) |
| 5900 | 6973 | { |
@@ -5917,9 +6990,18 @@ discard block |
||
| 5917 | 6990 | if ($_winmail_nr == $wantedPart.'@'.$mime_id) |
| 5918 | 6991 | { |
| 5919 | 6992 | //error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment)); |
| 5920 | - if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName(); |
|
| 5921 | - if (($cid = $part->getContentId())) $attachment['cid'] = $cid; |
|
| 5922 | - 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']); |
|
| 6993 | + if (!isset($attachment['filename'])||empty($attachment['filename'])) |
|
| 6994 | + { |
|
| 6995 | + $attachment['filename'] = $part->getName(); |
|
| 6996 | + } |
|
| 6997 | + if (($cid = $part->getContentId())) |
|
| 6998 | + { |
|
| 6999 | + $attachment['cid'] = $cid; |
|
| 7000 | + } |
|
| 7001 | + if (empty($attachment['filename'])) |
|
| 7002 | + { |
|
| 7003 | + $attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']); |
|
| 7004 | + } |
|
| 5923 | 7005 | $wmattach = $attachment; |
| 5924 | 7006 | $wmattach['attachment'] = $part->getContents(array('stream'=>$_stream)); |
| 5925 | 7007 | |
@@ -5929,7 +7011,10 @@ discard block |
||
| 5929 | 7011 | if ($tnefResolved) |
| 5930 | 7012 | { |
| 5931 | 7013 | $ext = MimeMagic::mime2ext($wmattach['mimeType']); |
| 5932 | - if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext; |
|
| 7014 | + if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) |
|
| 7015 | + { |
|
| 7016 | + $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext; |
|
| 7017 | + } |
|
| 5933 | 7018 | $attachmentData = array( |
| 5934 | 7019 | 'type' => $wmattach['mimeType'], |
| 5935 | 7020 | 'filename' => $wmattach['filename'], |
@@ -5959,7 +7044,10 @@ discard block |
||
| 5959 | 7044 | static $uid=null, $part=null, $structure=null; |
| 5960 | 7045 | //error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part"); |
| 5961 | 7046 | |
| 5962 | - if(empty($_cid)) return false; |
|
| 7047 | + if(empty($_cid)) |
|
| 7048 | + { |
|
| 7049 | + return false; |
|
| 7050 | + } |
|
| 5963 | 7051 | |
| 5964 | 7052 | if ($_uid != $uid || $_part != $part) |
| 5965 | 7053 | { |
@@ -5984,13 +7072,19 @@ discard block |
||
| 5984 | 7072 | $attachment = $part; |
| 5985 | 7073 | } |
| 5986 | 7074 | // everything else we only consider after we checked all |
| 5987 | - if (!isset($attachment)) $attachment = $part; |
|
| 7075 | + if (!isset($attachment)) |
|
| 7076 | + { |
|
| 7077 | + $attachment = $part; |
|
| 7078 | + } |
|
| 5988 | 7079 | // do we want content fetched, can be done later, if not needed |
| 5989 | 7080 | if (isset($_stream)) |
| 5990 | 7081 | { |
| 5991 | 7082 | $this->fetchPartContents($_uid, $attachment, $_stream); |
| 5992 | 7083 | } |
| 5993 | - if (isset($attachment)) break; |
|
| 7084 | + if (isset($attachment)) |
|
| 7085 | + { |
|
| 7086 | + break; |
|
| 7087 | + } |
|
| 5994 | 7088 | } |
| 5995 | 7089 | } |
| 5996 | 7090 | // set name as filename, if not set |
@@ -6021,10 +7115,17 @@ discard block |
||
| 6021 | 7115 | */ |
| 6022 | 7116 | public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null) |
| 6023 | 7117 | { |
| 6024 | - if (is_null($part)) return null;//new Horde_Mime_Part; |
|
| 7118 | + if (is_null($part)) |
|
| 7119 | + { |
|
| 7120 | + return null; |
|
| 7121 | + } |
|
| 7122 | + //new Horde_Mime_Part; |
|
| 6025 | 7123 | $encoding = null; |
| 6026 | 7124 | $fetchAsBinary = true; |
| 6027 | - if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false; |
|
| 7125 | + if ($_mimetype && strtolower($_mimetype)=='message/rfc822') |
|
| 7126 | + { |
|
| 7127 | + $fetchAsBinary = false; |
|
| 7128 | + } |
|
| 6028 | 7129 | // we need to set content on structure to decode transfer encoding |
| 6029 | 7130 | $part->setContents( |
| 6030 | 7131 | $this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary), |
@@ -6061,7 +7162,10 @@ discard block |
||
| 6061 | 7162 | // the recent flag is the default enforced here ; as we assume the _flags is always set, |
| 6062 | 7163 | // we default it to hordes default (Recent) (, other wise we should not pass the parameter |
| 6063 | 7164 | // for flags at all) |
| 6064 | - if (empty($_flags)) $_flags = '\\Recent'; |
|
| 7165 | + if (empty($_flags)) |
|
| 7166 | + { |
|
| 7167 | + $_flags = '\\Recent'; |
|
| 7168 | + } |
|
| 6065 | 7169 | //if (!is_array($_flags) && stripos($_flags,',')!==false) $_flags=explode(',',$_flags); |
| 6066 | 7170 | //if (!is_array($_flags)) $_flags = (array) $_flags; |
| 6067 | 7171 | try |
@@ -6078,18 +7182,27 @@ discard block |
||
| 6078 | 7182 | } |
| 6079 | 7183 | catch (\Exception $e) |
| 6080 | 7184 | { |
| 6081 | - if (self::$debug) error_log("Could not append Message: ".$e->getMessage()); |
|
| 7185 | + if (self::$debug) |
|
| 7186 | + { |
|
| 7187 | + error_log("Could not append Message: ".$e->getMessage()); |
|
| 7188 | + } |
|
| 6082 | 7189 | throw new Exception\WrongUserinput(lang("Could not append Message:").' '.$e->getMessage().': '.$e->details); |
| 6083 | 7190 | //return false; |
| 6084 | 7191 | } |
| 6085 | 7192 | //error_log(__METHOD__.' ('.__LINE__.') '.' appended UID:'.$messageid); |
| 6086 | 7193 | //$messageid = true; // for debug reasons only |
| 6087 | - if ($messageid === true || empty($messageid)) // try to figure out the message uid |
|
| 7194 | + if ($messageid === true || empty($messageid)) |
|
| 7195 | + { |
|
| 7196 | + // try to figure out the message uid |
|
| 6088 | 7197 | { |
| 6089 | 7198 | $list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false); |
| 7199 | + } |
|
| 6090 | 7200 | if ($list) |
| 6091 | 7201 | { |
| 6092 | - if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list)); |
|
| 7202 | + if (self::$debug) |
|
| 7203 | + { |
|
| 7204 | + error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list)); |
|
| 7205 | + } |
|
| 6093 | 7206 | $messageid = $list['header'][0]['uid']; |
| 6094 | 7207 | } |
| 6095 | 7208 | } |
@@ -6130,7 +7243,10 @@ discard block |
||
| 6130 | 7243 | { |
| 6131 | 7244 | //echo __METHOD__." called for $uid,$partid <br>"; |
| 6132 | 7245 | $headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox); |
| 6133 | - if (empty($headers)) return false; |
|
| 7246 | + if (empty($headers)) |
|
| 7247 | + { |
|
| 7248 | + return false; |
|
| 7249 | + } |
|
| 6134 | 7250 | // dont force retrieval of the textpart, let mailClass preferences decide |
| 6135 | 7251 | $bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox); |
| 6136 | 7252 | // if we do not want HTML but there is no TextRepresentation with the message itself, try converting |
@@ -6148,15 +7264,30 @@ discard block |
||
| 6148 | 7264 | //error_log(array2string($bodyParts)); |
| 6149 | 7265 | $attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array(); |
| 6150 | 7266 | |
| 6151 | - if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO']; |
|
| 6152 | - elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM']; |
|
| 6153 | - elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER']; |
|
| 6154 | - if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC']; |
|
| 7267 | + if ($mailClass->isSentFolder($mailbox)) |
|
| 7268 | + { |
|
| 7269 | + $mailaddress = $headers['TO']; |
|
| 7270 | + } |
|
| 7271 | + elseif (isset($headers['FROM'])) |
|
| 7272 | + { |
|
| 7273 | + $mailaddress = $headers['FROM']; |
|
| 7274 | + } |
|
| 7275 | + elseif (isset($headers['SENDER'])) |
|
| 7276 | + { |
|
| 7277 | + $mailaddress = $headers['SENDER']; |
|
| 7278 | + } |
|
| 7279 | + if (isset($headers['CC'])) |
|
| 7280 | + { |
|
| 7281 | + $mailaddress .= ','.$headers['CC']; |
|
| 7282 | + } |
|
| 6155 | 7283 | //_debug_array(array($headers,$mailaddress)); |
| 6156 | 7284 | $subject = $headers['SUBJECT']; |
| 6157 | 7285 | |
| 6158 | 7286 | $message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML); |
| 6159 | - if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>'; |
|
| 7287 | + if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') |
|
| 7288 | + { |
|
| 7289 | + $message = '<pre>'.$message.'</pre>'; |
|
| 7290 | + } |
|
| 6160 | 7291 | $headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : ''); |
| 6161 | 7292 | $message = $headdata.$message; |
| 6162 | 7293 | //echo __METHOD__.'<br>'; |
@@ -6207,7 +7338,8 @@ discard block |
||
| 6207 | 7338 | $attachments[$num]['attachment'] = $c->getContents(); |
| 6208 | 7339 | } |
| 6209 | 7340 | // no attempt to convert, if we dont know about the charset |
| 6210 | - if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) { |
|
| 7341 | + if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) |
|
| 7342 | + { |
|
| 6211 | 7343 | // we do not try guessing the charset, if it is not set |
| 6212 | 7344 | //if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']); |
| 6213 | 7345 | Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']); |
@@ -6228,7 +7360,10 @@ discard block |
||
| 6228 | 7360 | unset($attachments[$num]['attachment']); |
| 6229 | 7361 | } |
| 6230 | 7362 | } |
| 6231 | - if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages); |
|
| 7363 | + if (is_array($attachedMessages)) |
|
| 7364 | + { |
|
| 7365 | + $attachments = array_merge($attachments,$attachedMessages); |
|
| 7366 | + } |
|
| 6232 | 7367 | } |
| 6233 | 7368 | return array( |
| 6234 | 7369 | 'mailaddress'=>$mailaddress, |
@@ -6250,10 +7385,17 @@ discard block |
||
| 6250 | 7385 | { |
| 6251 | 7386 | $c = 0; |
| 6252 | 7387 | // use the standardIdentity |
| 6253 | - foreach($_identities as $key => $acc) { |
|
| 6254 | - if ($c==0) $identity = $acc; |
|
| 7388 | + foreach($_identities as $key => $acc) |
|
| 7389 | + { |
|
| 7390 | + if ($c==0) |
|
| 7391 | + { |
|
| 7392 | + $identity = $acc; |
|
| 7393 | + } |
|
| 6255 | 7394 | //error_log(__METHOD__.__LINE__." $key == $_profile_id "); |
| 6256 | - if ($key==$_profile_id) $identity = $acc; |
|
| 7395 | + if ($key==$_profile_id) |
|
| 7396 | + { |
|
| 7397 | + $identity = $acc; |
|
| 7398 | + } |
|
| 6257 | 7399 | $c++; |
| 6258 | 7400 | } |
| 6259 | 7401 | return $identity; |
@@ -6269,20 +7411,53 @@ discard block |
||
| 6269 | 7411 | { |
| 6270 | 7412 | $headdata = null; |
| 6271 | 7413 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace()); |
| 6272 | - if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n"); |
|
| 6273 | - if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 6274 | - if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 6275 | - if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 6276 | - if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 6277 | - if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 6278 | - if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n"); |
|
| 6279 | - if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n"); |
|
| 6280 | - if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n"); |
|
| 7414 | + if ($header['SUBJECT']) |
|
| 7415 | + { |
|
| 7416 | + $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n"); |
|
| 7417 | + } |
|
| 7418 | + if ($header['FROM']) |
|
| 7419 | + { |
|
| 7420 | + $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 7421 | + } |
|
| 7422 | + if ($header['SENDER']) |
|
| 7423 | + { |
|
| 7424 | + $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 7425 | + } |
|
| 7426 | + if ($header['TO']) |
|
| 7427 | + { |
|
| 7428 | + $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 7429 | + } |
|
| 7430 | + if ($header['CC']) |
|
| 7431 | + { |
|
| 7432 | + $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 7433 | + } |
|
| 7434 | + if ($header['BCC']) |
|
| 7435 | + { |
|
| 7436 | + $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n"); |
|
| 7437 | + } |
|
| 7438 | + if ($header['DATE']) |
|
| 7439 | + { |
|
| 7440 | + $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n"); |
|
| 7441 | + } |
|
| 7442 | + if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') |
|
| 7443 | + { |
|
| 7444 | + $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n"); |
|
| 7445 | + } |
|
| 7446 | + if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') |
|
| 7447 | + { |
|
| 7448 | + $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n"); |
|
| 7449 | + } |
|
| 6281 | 7450 | //if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\ |
| 6282 | 7451 | if (!empty($headdata)) |
| 6283 | 7452 | { |
| 6284 | - if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata; |
|
| 6285 | - if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata; |
|
| 7453 | + if (!empty($headline) && $headline != 'SUPPRESS') |
|
| 7454 | + { |
|
| 7455 | + $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata; |
|
| 7456 | + } |
|
| 7457 | + if (empty($headline)) |
|
| 7458 | + { |
|
| 7459 | + $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata; |
|
| 7460 | + } |
|
| 6286 | 7461 | $headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):''); |
| 6287 | 7462 | } |
| 6288 | 7463 | else |
@@ -6316,12 +7491,15 @@ discard block |
||
| 6316 | 7491 | $returnAddr =''; |
| 6317 | 7492 | if (is_array($rfcAddressArray)) |
| 6318 | 7493 | { |
| 6319 | - foreach((array)$rfcAddressArray as $addressData) { |
|
| 7494 | + foreach((array)$rfcAddressArray as $addressData) |
|
| 7495 | + { |
|
| 6320 | 7496 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData)); |
| 6321 | - if($addressData['MAILBOX_NAME'] == 'NIL') { |
|
| 7497 | + if($addressData['MAILBOX_NAME'] == 'NIL') |
|
| 7498 | + { |
|
| 6322 | 7499 | continue; |
| 6323 | 7500 | } |
| 6324 | - if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') { |
|
| 7501 | + if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') |
|
| 7502 | + { |
|
| 6325 | 7503 | continue; |
| 6326 | 7504 | } |
| 6327 | 7505 | if ($addressData['RFC822_EMAIL']) |
@@ -6335,7 +7513,10 @@ discard block |
||
| 6335 | 7513 | } |
| 6336 | 7514 | $addressObject = $addressObjectA[0]; |
| 6337 | 7515 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressObject)); |
| 6338 | - if (!$addressObject->valid) continue; |
|
| 7516 | + if (!$addressObject->valid) |
|
| 7517 | + { |
|
| 7518 | + continue; |
|
| 7519 | + } |
|
| 6339 | 7520 | //$mb =(string)$addressObject->mailbox; |
| 6340 | 7521 | //$h = (string)$addressObject->host; |
| 6341 | 7522 | //$p = (string)$addressObject->personal; |
@@ -6352,7 +7533,10 @@ discard block |
||
| 6352 | 7533 | // do not mess with strings, return them untouched /* ToDo: validate string as Address */ |
| 6353 | 7534 | $rfcAddressArray = self::decode_header($rfcAddressArray,true); |
| 6354 | 7535 | $rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray); |
| 6355 | - if (is_string($rfcAddressArray)) return $rfcAddressArray; |
|
| 7536 | + if (is_string($rfcAddressArray)) |
|
| 7537 | + { |
|
| 7538 | + return $rfcAddressArray; |
|
| 7539 | + } |
|
| 6356 | 7540 | } |
| 6357 | 7541 | return $returnAddr; |
| 6358 | 7542 | } |
@@ -6369,10 +7553,19 @@ discard block |
||
| 6369 | 7553 | { |
| 6370 | 7554 | $mergeobj = new Contacts\Merge(); |
| 6371 | 7555 | |
| 6372 | - if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html'); |
|
| 7556 | + if (empty($mimetype)) |
|
| 7557 | + { |
|
| 7558 | + $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html'); |
|
| 7559 | + } |
|
| 6373 | 7560 | $rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset); |
| 6374 | - if (empty($rv) && !empty($content) && !empty($err)) $rv = $content; |
|
| 6375 | - if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err)); |
|
| 7561 | + if (empty($rv) && !empty($content) && !empty($err)) |
|
| 7562 | + { |
|
| 7563 | + $rv = $content; |
|
| 7564 | + } |
|
| 7565 | + if (!empty($err) && !empty($content) && !empty($ids)) |
|
| 7566 | + { |
|
| 7567 | + error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err)); |
|
| 7568 | + } |
|
| 6376 | 7569 | return $rv; |
| 6377 | 7570 | } |
| 6378 | 7571 | |
@@ -6409,13 +7602,15 @@ discard block |
||
| 6409 | 7602 | settype($bytes, 'integer'); |
| 6410 | 7603 | $bytes /= 10; |
| 6411 | 7604 | } |
| 6412 | - else |
|
| 6413 | - settype($bytes, 'integer'); |
|
| 7605 | + else { |
|
| 7606 | + settype($bytes, 'integer'); |
|
| 7607 | + } |
|
| 6414 | 7608 | |
| 6415 | 7609 | return $bytes . ' ' . $type ; |
| 6416 | 7610 | } |
| 6417 | 7611 | |
| 6418 | - static function detect_qp(&$sting) { |
|
| 7612 | + static function detect_qp(&$sting) |
|
| 7613 | + { |
|
| 6419 | 7614 | $needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/'; |
| 6420 | 7615 | return preg_match("$needle",$string); |
| 6421 | 7616 | } |
@@ -6432,9 +7627,15 @@ discard block |
||
| 6432 | 7627 | */ |
| 6433 | 7628 | static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='') |
| 6434 | 7629 | { |
| 6435 | - if (is_null($_endtime)) $_endtime = microtime(true); |
|
| 7630 | + if (is_null($_endtime)) |
|
| 7631 | + { |
|
| 7632 | + $_endtime = microtime(true); |
|
| 7633 | + } |
|
| 6436 | 7634 | $usagetime = microtime(true) - $_starttime; |
| 6437 | - if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:'')); |
|
| 7635 | + if (self::$debugTimes) |
|
| 7636 | + { |
|
| 7637 | + error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:'')); |
|
| 7638 | + } |
|
| 6438 | 7639 | } |
| 6439 | 7640 | |
| 6440 | 7641 | /** |
@@ -6449,7 +7650,10 @@ discard block |
||
| 6449 | 7650 | */ |
| 6450 | 7651 | static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822') |
| 6451 | 7652 | { |
| 6452 | - if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file']; |
|
| 7653 | + if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') |
|
| 7654 | + { |
|
| 7655 | + return $_formData['file']; |
|
| 7656 | + } |
|
| 6453 | 7657 | |
| 6454 | 7658 | //error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType); |
| 6455 | 7659 | $importfailed = $tmpFileName = false; |
@@ -6498,8 +7702,15 @@ discard block |
||
| 6498 | 7702 | { |
| 6499 | 7703 | $buff = explode('.',$_formData['name']); |
| 6500 | 7704 | $suffix = ''; |
| 6501 | - if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime |
|
| 6502 | - if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix); |
|
| 7705 | + if (is_array($buff)) |
|
| 7706 | + { |
|
| 7707 | + $suffix = array_pop($buff); |
|
| 7708 | + } |
|
| 7709 | + // take the last extension to check with ext2mime |
|
| 7710 | + if (!empty($suffix)) |
|
| 7711 | + { |
|
| 7712 | + $sfxMimeType = MimeMagic::ext2mime($suffix); |
|
| 7713 | + } |
|
| 6503 | 7714 | if (!empty($suffix) && !empty($sfxMimeType) && |
| 6504 | 7715 | (strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType))) |
| 6505 | 7716 | { |
@@ -6547,7 +7758,9 @@ discard block |
||
| 6547 | 7758 | { |
| 6548 | 7759 | rename($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName); |
| 6549 | 7760 | } |
| 6550 | - } else { |
|
| 7761 | + } |
|
| 7762 | + else |
|
| 7763 | + { |
|
| 6551 | 7764 | //error_log("Import of message ".$_formData['file']." failes to meet basic restrictions"); |
| 6552 | 7765 | $importfailed = true; |
| 6553 | 7766 | $alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']); |
@@ -6593,21 +7806,32 @@ discard block |
||
| 6593 | 7806 | if (substr($url, 0, 5) !== 'data:') |
| 6594 | 7807 | { |
| 6595 | 7808 | $filename = basename($url); |
| 6596 | - if (($directory = dirname($url)) == '.') $directory = ''; |
|
| 7809 | + if (($directory = dirname($url)) == '.') |
|
| 7810 | + { |
|
| 7811 | + $directory = ''; |
|
| 7812 | + } |
|
| 6597 | 7813 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
| 6598 | 7814 | $mimeType = MimeMagic::ext2mime($ext); |
| 6599 | - if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } |
|
| 7815 | + if ( strlen($directory) > 1 && substr($directory,-1) != '/') |
|
| 7816 | + { |
|
| 7817 | +$directory .= '/'; } |
|
| 6600 | 7818 | $myUrl = $directory.$filename; |
| 6601 | - if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs) |
|
| 7819 | + if ($myUrl[0]=='/') |
|
| 7820 | + { |
|
| 7821 | + // local path -> we only allow path's that are available via http/https (or vfs) |
|
| 6602 | 7822 | { |
| 6603 | 7823 | $basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']); |
| 6604 | 7824 | } |
| 7825 | + } |
|
| 6605 | 7826 | // use vfs instead of url containing webdav.php |
| 6606 | 7827 | // ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign |
| 6607 | 7828 | // webdav.php urls as vfs |
| 6608 | - if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it. |
|
| 7829 | + if (strpos($myUrl,'/webdav.php') !== false) |
|
| 7830 | + { |
|
| 7831 | + // we have a webdav link, so we build a vfs/sqlfs link of it. |
|
| 6609 | 7832 | { |
| 6610 | 7833 | Vfs::load_wrapper('vfs'); |
| 7834 | + } |
|
| 6611 | 7835 | list(,$myUrl) = explode('/webdav.php',$myUrl,2); |
| 6612 | 7836 | $basedir = 'vfs://default'; |
| 6613 | 7837 | $needTempFile = false; |
@@ -6636,8 +7860,13 @@ discard block |
||
| 6636 | 7860 | } |
| 6637 | 7861 | } |
| 6638 | 7862 | |
| 6639 | - if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; } |
|
| 6640 | - if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl)); |
|
| 7863 | + if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') |
|
| 7864 | + { |
|
| 7865 | +$basedir .= '/'; } |
|
| 7866 | + if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") |
|
| 7867 | + { |
|
| 7868 | + $data = file_get_contents($basedir.urldecode($myUrl)); |
|
| 7869 | + } |
|
| 6641 | 7870 | } |
| 6642 | 7871 | if (substr($url,0,strlen('data:'))=='data:') |
| 6643 | 7872 | { |
@@ -6745,7 +7974,10 @@ discard block |
||
| 6745 | 7974 | $_folder = $this->getSentFolder(); |
| 6746 | 7975 | } |
| 6747 | 7976 | $delimiter = $this->getHierarchyDelimiter(); |
| 6748 | - if($_folder=='INBOX'.$delimiter) $_folder='INBOX'; |
|
| 7977 | + if($_folder=='INBOX'.$delimiter) |
|
| 7978 | + { |
|
| 7979 | + $_folder='INBOX'; |
|
| 7980 | + } |
|
| 6749 | 7981 | if ($importfailed === false) |
| 6750 | 7982 | { |
| 6751 | 7983 | $Subject = $mailObject->getHeader('Subject'); |
@@ -6774,7 +8006,9 @@ discard block |
||
| 6774 | 8006 | //error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val); |
| 6775 | 8007 | if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/ |
| 6776 | 8008 | count($SendAndMergeTocontacts) > 1 && $val && |
| 6777 | - (is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge |
|
| 8009 | + (is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) |
|
| 8010 | + { |
|
| 8011 | + // do the merge |
|
| 6778 | 8012 | { |
| 6779 | 8013 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject)); |
| 6780 | 8014 | |
@@ -6783,6 +8017,7 @@ discard block |
||
| 6783 | 8017 | { |
| 6784 | 8018 | //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)); |
| 6785 | 8019 | $merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset); |
| 8020 | + } |
|
| 6786 | 8021 | $mailObject->addAddress($merged,'',$type); |
| 6787 | 8022 | if($type == 'to') |
| 6788 | 8023 | { |
@@ -6814,9 +8049,15 @@ discard block |
||
| 6814 | 8049 | $mailObject->clearCustomHeaders(); |
| 6815 | 8050 | $mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset)); |
| 6816 | 8051 | //error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType); |
| 6817 | - 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)); |
|
| 8052 | + if($text_body) |
|
| 8053 | + { |
|
| 8054 | + $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); |
|
| 8055 | + } |
|
| 6818 | 8056 | //error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e)); |
| 6819 | - 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)); |
|
| 8057 | + if($html_body) |
|
| 8058 | + { |
|
| 8059 | + $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); |
|
| 8060 | + } |
|
| 6820 | 8061 | |
| 6821 | 8062 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject)); |
| 6822 | 8063 | // set a higher timeout for big messages |
@@ -6831,9 +8072,12 @@ discard block |
||
| 6831 | 8072 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo)); |
| 6832 | 8073 | } |
| 6833 | 8074 | } |
| 6834 | - elseif (!$k) // 1. entry, further entries will fail for apps other then addressbook |
|
| 8075 | + elseif (!$k) |
|
| 8076 | + { |
|
| 8077 | + // 1. entry, further entries will fail for apps other then addressbook |
|
| 6835 | 8078 | { |
| 6836 | 8079 | $openAsDraft = true; |
| 8080 | + } |
|
| 6837 | 8081 | $mailObject->removeHeader('Message-ID'); |
| 6838 | 8082 | $mailObject->removeHeader('Date'); |
| 6839 | 8083 | $mailObject->clearCustomHeaders(); |
@@ -6848,9 +8092,12 @@ discard block |
||
| 6848 | 8092 | |
| 6849 | 8093 | // No addresses from placeholders? Treat it as just a contact ID |
| 6850 | 8094 | if (count($mailObject->getAddresses('to',true)) == 0 && |
| 6851 | - is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge |
|
| 8095 | + is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) |
|
| 8096 | + { |
|
| 8097 | + // do the merge |
|
| 6852 | 8098 | { |
| 6853 | 8099 | $contact = $bo_merge->contacts->read($val); |
| 8100 | + } |
|
| 6854 | 8101 | //error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact)); |
| 6855 | 8102 | $email = ($contact['email'] ? $contact['email'] : $contact['email_home']); |
| 6856 | 8103 | $nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']); |
@@ -6861,9 +8108,15 @@ discard block |
||
| 6861 | 8108 | } |
| 6862 | 8109 | $mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset)); |
| 6863 | 8110 | //error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType); |
| 6864 | - 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)); |
|
| 8111 | + if (!empty($Body)) |
|
| 8112 | + { |
|
| 8113 | + $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); |
|
| 8114 | + } |
|
| 6865 | 8115 | //error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e)); |
| 6866 | - 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)); |
|
| 8116 | + if (!empty($AltBody)) |
|
| 8117 | + { |
|
| 8118 | + $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); |
|
| 8119 | + } |
|
| 6867 | 8120 | $_folder = $this->getDraftFolder(); |
| 6868 | 8121 | } |
| 6869 | 8122 | if ($sendOK || $openAsDraft) |
@@ -6871,11 +8124,15 @@ discard block |
||
| 6871 | 8124 | if ($this->folderExists($_folder,true)) |
| 6872 | 8125 | { |
| 6873 | 8126 | if($this->isSentFolder($_folder)) |
| 6874 | - { |
|
| 8127 | + { |
|
| 6875 | 8128 | $flags = '\\Seen'; |
| 6876 | - } elseif($this->isDraftFolder($_folder)) { |
|
| 8129 | + } |
|
| 8130 | + elseif($this->isDraftFolder($_folder)) |
|
| 8131 | + { |
|
| 6877 | 8132 | $flags = '\\Draft'; |
| 6878 | - } else { |
|
| 8133 | + } |
|
| 8134 | + else |
|
| 8135 | + { |
|
| 6879 | 8136 | $flags = ''; |
| 6880 | 8137 | } |
| 6881 | 8138 | $savefailed = false; |
@@ -6909,7 +8166,10 @@ discard block |
||
| 6909 | 8166 | } |
| 6910 | 8167 | else |
| 6911 | 8168 | { |
| 6912 | - if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details'; |
|
| 8169 | + if (!$openComposeWindow) |
|
| 8170 | + { |
|
| 8171 | + $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details'; |
|
| 8172 | + } |
|
| 6913 | 8173 | } |
| 6914 | 8174 | } |
| 6915 | 8175 | if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow)) |
@@ -6957,7 +8217,10 @@ discard block |
||
| 6957 | 8217 | $tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($tmpFileName); |
| 6958 | 8218 | break; |
| 6959 | 8219 | } |
| 6960 | - if (!isset($message)) $message = fopen($tmpFileName, 'r'); |
|
| 8220 | + if (!isset($message)) |
|
| 8221 | + { |
|
| 8222 | + $message = fopen($tmpFileName, 'r'); |
|
| 8223 | + } |
|
| 6961 | 8224 | |
| 6962 | 8225 | if (!$message) |
| 6963 | 8226 | { |
@@ -6996,7 +8259,10 @@ discard block |
||
| 6996 | 8259 | (fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192)); |
| 6997 | 8260 | |
| 6998 | 8261 | $length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL); |
| 6999 | - if ($length===false) $length = strlen($start); |
|
| 8262 | + if ($length===false) |
|
| 8263 | + { |
|
| 8264 | + $length = strlen($start); |
|
| 8265 | + } |
|
| 7000 | 8266 | $headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length)); |
| 7001 | 8267 | |
| 7002 | 8268 | foreach($headers->toArray(array('nowrap' => true)) as $header => $value) |
@@ -7014,7 +8280,10 @@ discard block |
||
| 7014 | 8280 | break; |
| 7015 | 8281 | default: |
| 7016 | 8282 | //error_log(__METHOD__.__LINE__.':'.$header.'->'.$val); |
| 7017 | - if (strtolower($header)=='bcc') $bccAddresses .= $val; |
|
| 8283 | + if (strtolower($header)=='bcc') |
|
| 8284 | + { |
|
| 8285 | + $bccAddresses .= $val; |
|
| 8286 | + } |
|
| 7018 | 8287 | $mailer->addHeader($header, $val, $overwrite); |
| 7019 | 8288 | //error_log(__METHOD__.__LINE__.':'.'getHeader('.$header.')'.array2string($mailer->getHeader($header)).(strtolower($header)=='bcc'?$bccAddresses:'')); |
| 7020 | 8289 | } |
@@ -7027,7 +8296,10 @@ discard block |
||
| 7027 | 8296 | } |
| 7028 | 8297 | else |
| 7029 | 8298 | { |
| 7030 | - if (($type = gettype($message)) == 'object') $type = get_class ($message); |
|
| 8299 | + if (($type = gettype($message)) == 'object') |
|
| 8300 | + { |
|
| 8301 | + $type = get_class ($message); |
|
| 8302 | + } |
|
| 7031 | 8303 | throw new Exception\WrongParameter('Wrong parameter type for message: '.$type); |
| 7032 | 8304 | } |
| 7033 | 8305 | } |
@@ -7051,7 +8323,9 @@ discard block |
||
| 7051 | 8323 | $matches = array(); |
| 7052 | 8324 | preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches); |
| 7053 | 8325 | //error_log(__METHOD__.__LINE__.array2string($matches)); |
| 7054 | - foreach ($matches[0] as &$match) {$match = trim($match,', ');} |
|
| 8326 | + foreach ($matches[0] as &$match) |
|
| 8327 | + { |
|
| 8328 | +$match = trim($match,', ');} |
|
| 7055 | 8329 | $addresses = implode(',',$matches[0]); |
| 7056 | 8330 | //error_log(__METHOD__.__LINE__.array2string($addresses)); |
| 7057 | 8331 | $ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array()); |
@@ -7082,7 +8356,10 @@ discard block |
||
| 7082 | 8356 | } |
| 7083 | 8357 | else |
| 7084 | 8358 | { |
| 7085 | - if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal; |
|
| 8359 | + if ($previousFailed && $remember) |
|
| 8360 | + { |
|
| 8361 | + $adr->personal = $remember. ' ' . $adr->personal; |
|
| 8362 | + } |
|
| 7086 | 8363 | $remember = ''; |
| 7087 | 8364 | $previousFailed=false; |
| 7088 | 8365 | //error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal"); |
@@ -7104,7 +8381,10 @@ discard block |
||
| 7104 | 8381 | { |
| 7105 | 8382 | $acc = Mail\Account::read($this->profileID); |
| 7106 | 8383 | $identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc); |
| 7107 | - if (self::$debug) error_log(__METHOD__.__LINE__.array2string($identity)); |
|
| 8384 | + if (self::$debug) |
|
| 8385 | + { |
|
| 8386 | + error_log(__METHOD__.__LINE__.array2string($identity)); |
|
| 8387 | + } |
|
| 7108 | 8388 | $headers = $this->getMessageHeader($uid, '', 'object', true, $_folder); |
| 7109 | 8389 | |
| 7110 | 8390 | $mdn = new Horde_Mime_Mdn($headers); |
@@ -84,29 +84,47 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function __construct(activesync_backend $backend) |
| 86 | 86 | { |
| 87 | - if ($GLOBALS['egw_setup']) return; |
|
| 87 | + if ($GLOBALS['egw_setup']) |
|
| 88 | + { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 88 | 91 | |
| 89 | 92 | //$this->debugLevel=2; |
| 90 | 93 | $this->backend = $backend; |
| 91 | 94 | if (!isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'])) |
| 92 | 95 | { |
| 93 | - if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default'); |
|
| 96 | + if ($this->debugLevel>1) |
|
| 97 | + { |
|
| 98 | + error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default'); |
|
| 99 | + } |
|
| 94 | 100 | // globals preferences add appname varname value |
| 95 | 101 | $GLOBALS['egw']->preferences->add('activesync','mail-ActiveSyncProfileID',0,'user'); |
| 96 | 102 | // save prefs |
| 97 | 103 | $GLOBALS['egw']->preferences->save_repository(true); |
| 98 | 104 | } |
| 99 | - if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID)); |
|
| 105 | + if ($this->debugLevel>1) |
|
| 106 | + { |
|
| 107 | + error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID)); |
|
| 108 | + } |
|
| 100 | 109 | |
| 101 | 110 | if (is_null(self::$profileID)) |
| 102 | 111 | { |
| 103 | - if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID)); |
|
| 112 | + if ($this->debugLevel>1) |
|
| 113 | + { |
|
| 114 | + error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID)); |
|
| 115 | + } |
|
| 104 | 116 | self::$profileID =& Api\Cache::getSession('mail','activeSyncProfileID'); |
| 105 | - if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID)); |
|
| 117 | + if ($this->debugLevel>1) |
|
| 118 | + { |
|
| 119 | + error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID)); |
|
| 120 | + } |
|
| 106 | 121 | } |
| 107 | 122 | if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'])) |
| 108 | 123 | { |
| 109 | - if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'])); |
|
| 124 | + if ($this->debugLevel>1) |
|
| 125 | + { |
|
| 126 | + error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'])); |
|
| 127 | + } |
|
| 110 | 128 | if ($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'] == 'G') |
| 111 | 129 | { |
| 112 | 130 | self::$profileID = 'G'; // this should trigger the fetch of the first negative profile (or if no negative profile is available the firstb there is) |
@@ -116,7 +134,10 @@ discard block |
||
| 116 | 134 | self::$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']; |
| 117 | 135 | } |
| 118 | 136 | } |
| 119 | - if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID)); |
|
| 137 | + if ($this->debugLevel>1) |
|
| 138 | + { |
|
| 139 | + error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID)); |
|
| 140 | + } |
|
| 120 | 141 | |
| 121 | 142 | // verify we are on an existing profile, if not running in setup (settings can not be static according to interface!) |
| 122 | 143 | if (!isset($GLOBALS['egw_setup'])) |
@@ -129,7 +150,10 @@ discard block |
||
| 129 | 150 | self::$profileID = Mail\Account::get_default_acc_id(); |
| 130 | 151 | } |
| 131 | 152 | } |
| 132 | - if ($this->debugLevel>0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID); |
|
| 153 | + if ($this->debugLevel>0) |
|
| 154 | + { |
|
| 155 | + error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID); |
|
| 156 | + } |
|
| 133 | 157 | //$this->debugLevel=0; |
| 134 | 158 | } |
| 135 | 159 | |
@@ -245,8 +269,14 @@ discard block |
||
| 245 | 269 | $this->_connect(0,true); |
| 246 | 270 | $this->_disconnect(); |
| 247 | 271 | |
| 248 | - if (!$this->_wasteID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>'); |
|
| 249 | - if (!$this->_sentID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>'); |
|
| 272 | + if (!$this->_wasteID) |
|
| 273 | + { |
|
| 274 | + $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>'); |
|
| 275 | + } |
|
| 276 | + if (!$this->_sentID) |
|
| 277 | + { |
|
| 278 | + $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>'); |
|
| 279 | + } |
|
| 250 | 280 | } |
| 251 | 281 | catch(Exception $e) { |
| 252 | 282 | $errors[] = lang('Can not open IMAP connection').': '.$e->getMessage(); |
@@ -268,8 +298,14 @@ discard block |
||
| 268 | 298 | */ |
| 269 | 299 | private function _connect($account=0) |
| 270 | 300 | { |
| 271 | - if (!$account) $account = self::$profileID ? self::$profileID : 0; |
|
| 272 | - if ($this->mail && $this->account != $account) $this->_disconnect(); |
|
| 301 | + if (!$account) |
|
| 302 | + { |
|
| 303 | + $account = self::$profileID ? self::$profileID : 0; |
|
| 304 | + } |
|
| 305 | + if ($this->mail && $this->account != $account) |
|
| 306 | + { |
|
| 307 | + $this->_disconnect(); |
|
| 308 | + } |
|
| 273 | 309 | |
| 274 | 310 | $this->_wasteID = false; |
| 275 | 311 | $this->_sentID = false; |
@@ -280,12 +316,18 @@ discard block |
||
| 280 | 316 | // todo: tell mail which account to use |
| 281 | 317 | //error_log(__METHOD__.__LINE__.' create object with ProfileID:'.array2string(self::$profileID)); |
| 282 | 318 | $this->mail = Mail::getInstance(false,self::$profileID,true,false,true); |
| 283 | - if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId; |
|
| 319 | + if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) |
|
| 320 | + { |
|
| 321 | + self::$profileID = $this->mail->icServer->ImapServerId; |
|
| 322 | + } |
|
| 284 | 323 | } |
| 285 | 324 | else |
| 286 | 325 | { |
| 287 | 326 | //error_log(__METHOD__.__LINE__." connect with profileID: ".self::$profileID); |
| 288 | - if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId; |
|
| 327 | + if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) |
|
| 328 | + { |
|
| 329 | + self::$profileID = $this->mail->icServer->ImapServerId; |
|
| 330 | + } |
|
| 289 | 331 | } |
| 290 | 332 | $this->mail->openConnection(self::$profileID,false); |
| 291 | 333 | |
@@ -302,8 +344,14 @@ discard block |
||
| 302 | 344 | */ |
| 303 | 345 | private function _disconnect() |
| 304 | 346 | { |
| 305 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__); |
|
| 306 | - if ($this->mail) $this->mail->closeConnection(); |
|
| 347 | + if ($this->debugLevel>0) |
|
| 348 | + { |
|
| 349 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__); |
|
| 350 | + } |
|
| 351 | + if ($this->mail) |
|
| 352 | + { |
|
| 353 | + $this->mail->closeConnection(); |
|
| 354 | + } |
|
| 307 | 355 | |
| 308 | 356 | unset($this->mail); |
| 309 | 357 | unset($this->account); |
@@ -318,24 +366,43 @@ discard block |
||
| 318 | 366 | public function GetFolderList() |
| 319 | 367 | { |
| 320 | 368 | $folderlist = array(); |
| 321 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__); |
|
| 369 | + if ($this->debugLevel>0) |
|
| 370 | + { |
|
| 371 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__); |
|
| 372 | + } |
|
| 322 | 373 | /*foreach($available_accounts as $account)*/ $account = 0; |
| 323 | 374 | { |
| 324 | 375 | $this->_connect($account); |
| 325 | - if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true); |
|
| 326 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders)); |
|
| 376 | + if (!isset($this->folders)) |
|
| 377 | + { |
|
| 378 | + $this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true); |
|
| 379 | + } |
|
| 380 | + if ($this->debugLevel>1) |
|
| 381 | + { |
|
| 382 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders)); |
|
| 383 | + } |
|
| 327 | 384 | |
| 328 | - foreach ($this->folders as $folder => $folderObj) { |
|
| 329 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder); |
|
| 385 | + foreach ($this->folders as $folder => $folderObj) |
|
| 386 | + { |
|
| 387 | + if ($this->debugLevel>1) |
|
| 388 | + { |
|
| 389 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder); |
|
| 390 | + } |
|
| 330 | 391 | $folderlist[] = $f = array( |
| 331 | 392 | 'id' => $this->createID($account,$folder), |
| 332 | 393 | 'mod' => $folderObj->shortDisplayName, |
| 333 | 394 | 'parent' => $this->getParentID($account,$folder), |
| 334 | 395 | ); |
| 335 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f)); |
|
| 396 | + if ($this->debugLevel>1) |
|
| 397 | + { |
|
| 398 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f)); |
|
| 399 | + } |
|
| 336 | 400 | } |
| 337 | 401 | } |
| 338 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist)); |
|
| 402 | + if ($this->debugLevel>0) |
|
| 403 | + { |
|
| 404 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist)); |
|
| 405 | + } |
|
| 339 | 406 | |
| 340 | 407 | return $folderlist; |
| 341 | 408 | } |
@@ -396,11 +463,17 @@ discard block |
||
| 396 | 463 | $smartdata_task = ($smartdata->replyflag?'reply':($smartdata->forwardflag?'forward':'new')); |
| 397 | 464 | |
| 398 | 465 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__ . (isset($smartdata->mime) ? $smartdata->mime : ""). "task: ".(isset($smartdata_task) ? $smartdata_task : "")." itemid: ".(isset($smartdata->source->itemid) ? $smartdata->source->itemid : "")." folder: ".(isset($smartdata->source->folderid) ? $smartdata->source->folderid : "")); |
| 399 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata)); |
|
| 466 | + if ($this->debugLevel>0) |
|
| 467 | + { |
|
| 468 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata)); |
|
| 469 | + } |
|
| 400 | 470 | //error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata)); |
| 401 | 471 | |
| 402 | 472 | // initialize our Mail |
| 403 | - if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true); |
|
| 473 | + if (!isset($this->mail)) |
|
| 474 | + { |
|
| 475 | + $this->mail = Mail::getInstance(false,self::$profileID,true,false,true); |
|
| 476 | + } |
|
| 404 | 477 | $activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID); |
| 405 | 478 | // use the standardIdentity |
| 406 | 479 | $activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles,self::$profileID); |
@@ -428,12 +501,18 @@ discard block |
||
| 428 | 501 | $beforeHtml = ($disableRuler ?' <br>':' <br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">'); |
| 429 | 502 | $beforePlain = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n"); |
| 430 | 503 | $sigText = Mail::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id'))); |
| 431 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText); |
|
| 504 | + if ($this->debugLevel>0) |
|
| 505 | + { |
|
| 506 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText); |
|
| 507 | + } |
|
| 432 | 508 | $sigTextHtml = $beforeHtml.$sigText; |
| 433 | 509 | $sigTextPlain = $beforePlain.Api\Mail\Html::convertHTMLToText($sigText); |
| 434 | 510 | |
| 435 | 511 | $force8bit=false; |
| 436 | - if (Api\Translation::detect_encoding($sigTextPlain)!='ascii') $force8bit=true; |
|
| 512 | + if (Api\Translation::detect_encoding($sigTextPlain)!='ascii') |
|
| 513 | + { |
|
| 514 | + $force8bit=true; |
|
| 515 | + } |
|
| 437 | 516 | // initialize the new Api\Mailer object for sending |
| 438 | 517 | $mailObject = new Api\Mailer(self::$profileID); |
| 439 | 518 | $bccAddresses=''; |
@@ -445,22 +524,34 @@ discard block |
||
| 445 | 524 | |
| 446 | 525 | // prepare addressee list; moved the adding of addresses to the mailobject down |
| 447 | 526 | // to |
| 448 | - foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) { |
|
| 449 | - if (!$addressObject->valid) continue; |
|
| 527 | + foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) |
|
| 528 | + { |
|
| 529 | + if (!$addressObject->valid) |
|
| 530 | + { |
|
| 531 | + continue; |
|
| 532 | + } |
|
| 450 | 533 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) ); |
| 451 | 534 | //$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal); |
| 452 | 535 | $toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal); |
| 453 | 536 | } |
| 454 | 537 | // CC |
| 455 | - foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) { |
|
| 456 | - if (!$addressObject->valid) continue; |
|
| 538 | + foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) |
|
| 539 | + { |
|
| 540 | + if (!$addressObject->valid) |
|
| 541 | + { |
|
| 542 | + continue; |
|
| 543 | + } |
|
| 457 | 544 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) ); |
| 458 | 545 | //$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal); |
| 459 | 546 | $ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal); |
| 460 | 547 | } |
| 461 | 548 | // BCC |
| 462 | - foreach(Mail::parseAddressList(($bccAddresses?$bccAddresses:$mailObject->getHeader("Bcc"))) as $addressObject) { |
|
| 463 | - if (!$addressObject->valid) continue; |
|
| 549 | + foreach(Mail::parseAddressList(($bccAddresses?$bccAddresses:$mailObject->getHeader("Bcc"))) as $addressObject) |
|
| 550 | + { |
|
| 551 | + if (!$addressObject->valid) |
|
| 552 | + { |
|
| 553 | + continue; |
|
| 554 | + } |
|
| 464 | 555 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) ); |
| 465 | 556 | //$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal); |
| 466 | 557 | $bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal); |
@@ -473,12 +564,14 @@ discard block |
||
| 473 | 564 | $ContentType =$mailObject->getHeader('Content-Type'); |
| 474 | 565 | //error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k. " = ".trim($ContentType)); |
| 475 | 566 | // if the message is a multipart message, then we should use the sent body |
| 476 | - if (preg_match("/multipart/i", $ContentType)) { |
|
| 567 | + if (preg_match("/multipart/i", $ContentType)) |
|
| 568 | + { |
|
| 477 | 569 | $use_orgbody = true; |
| 478 | 570 | } |
| 479 | 571 | |
| 480 | 572 | // save the original content-type header for the body part when forwarding |
| 481 | - if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody) { |
|
| 573 | + if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody) |
|
| 574 | + { |
|
| 482 | 575 | //continue; // ignore |
| 483 | 576 | } |
| 484 | 577 | // horde/egw_ mailer does everything as utf-8, the following should not be needed |
@@ -487,7 +580,8 @@ discard block |
||
| 487 | 580 | // if the message is a multipart message, then we should use the sent body |
| 488 | 581 | if (($smartdata_task == 'new' || $smartdata_task == 'reply' || $smartdata_task == 'forward') && |
| 489 | 582 | ((isset($smartdata->replacemime) && $smartdata->replacemime == true) || |
| 490 | - $k == "Content-Type" && preg_match("/multipart/i", $ContentType))) { |
|
| 583 | + $k == "Content-Type" && preg_match("/multipart/i", $ContentType))) |
|
| 584 | + { |
|
| 491 | 585 | $use_orgbody = true; |
| 492 | 586 | } |
| 493 | 587 | $Body = $AltBody = ""; |
@@ -520,12 +614,19 @@ discard block |
||
| 520 | 614 | $AltBody = preg_replace("/(<|<)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|>)*/i","[$2]", |
| 521 | 615 | ($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null); |
| 522 | 616 | } |
| 523 | - if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body); |
|
| 524 | - if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody); |
|
| 617 | + if ($this->debugLevel>1 && $Body) |
|
| 618 | + { |
|
| 619 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body); |
|
| 620 | + } |
|
| 621 | + if ($this->debugLevel>1 && $AltBody) |
|
| 622 | + { |
|
| 623 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody); |
|
| 624 | + } |
|
| 525 | 625 | //error_log(__METHOD__.__LINE__.array2string($mailObject)); |
| 526 | 626 | // if this is a multipart message with a boundary, we must use the original body |
| 527 | 627 | //if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject)); |
| 528 | - if ($use_orgbody) { |
|
| 628 | + if ($use_orgbody) |
|
| 629 | + { |
|
| 529 | 630 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType); |
| 530 | 631 | // if it is a ClientSideMeetingRequest, we report it as send at all times |
| 531 | 632 | if (($cal_body = $mailObject->findBody('calendar')) && |
@@ -535,15 +636,20 @@ discard block |
||
| 535 | 636 | { |
| 536 | 637 | $organizer = calendar_ical::getIcalOrganizer($cal_body->getContents()); |
| 537 | 638 | } |
| 538 | - if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer"); |
|
| 639 | + if ($this->debugLevel) |
|
| 640 | + { |
|
| 641 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer"); |
|
| 642 | + } |
|
| 539 | 643 | $ClientSideMeetingRequest = true; |
| 540 | 644 | } |
| 541 | 645 | } |
| 542 | 646 | // now handle the addressee list |
| 543 | 647 | $toCount = 0; |
| 544 | 648 | //error_log(__METHOD__.__LINE__.array2string($toMailAddr)); |
| 545 | - foreach((array)$toMailAddr as $address) { |
|
| 546 | - foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) { |
|
| 649 | + foreach((array)$toMailAddr as $address) |
|
| 650 | + { |
|
| 651 | + foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) |
|
| 652 | + { |
|
| 547 | 653 | $emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''); |
| 548 | 654 | if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && |
| 549 | 655 | calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST', |
@@ -557,19 +663,29 @@ discard block |
||
| 557 | 663 | } |
| 558 | 664 | } |
| 559 | 665 | $ccCount = 0; |
| 560 | - foreach((array)$ccMailAddr as $address) { |
|
| 561 | - foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) { |
|
| 666 | + foreach((array)$ccMailAddr as $address) |
|
| 667 | + { |
|
| 668 | + foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) |
|
| 669 | + { |
|
| 562 | 670 | $emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''); |
| 563 | - if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue; |
|
| 671 | + if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) |
|
| 672 | + { |
|
| 673 | + continue; |
|
| 674 | + } |
|
| 564 | 675 | $mailObject->AddCC($emailAddress, $addressObject->personal); |
| 565 | 676 | $ccCount++; |
| 566 | 677 | } |
| 567 | 678 | } |
| 568 | 679 | $bccCount = 0; |
| 569 | - foreach((array)$bccMailAddr as $address) { |
|
| 570 | - foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) { |
|
| 680 | + foreach((array)$bccMailAddr as $address) |
|
| 681 | + { |
|
| 682 | + foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) |
|
| 683 | + { |
|
| 571 | 684 | $emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''); |
| 572 | - if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue; |
|
| 685 | + if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) |
|
| 686 | + { |
|
| 687 | + continue; |
|
| 688 | + } |
|
| 573 | 689 | $mailObject->AddBCC($emailAddress, $addressObject->personal); |
| 574 | 690 | $bccCount++; |
| 575 | 691 | } |
@@ -579,7 +695,10 @@ discard block |
||
| 579 | 695 | { |
| 580 | 696 | return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to |
| 581 | 697 | } |
| 582 | - if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true; |
|
| 698 | + if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) |
|
| 699 | + { |
|
| 700 | + return true; |
|
| 701 | + } |
|
| 583 | 702 | // as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail |
| 584 | 703 | /* |
| 585 | 704 | if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body); |
@@ -602,10 +721,17 @@ discard block |
||
| 602 | 721 | $this->mail->reopen($folder); |
| 603 | 722 | $bodyStruct = $this->mail->getMessageBody($uid, 'html_only'); |
| 604 | 723 | $bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false); |
| 605 | - if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml); |
|
| 606 | - if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) { |
|
| 724 | + if ($this->debugLevel>3) |
|
| 725 | + { |
|
| 726 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml); |
|
| 727 | + } |
|
| 728 | + if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) |
|
| 729 | + { |
|
| 607 | 730 | // may be html |
| 608 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml); |
|
| 731 | + if ($this->debugLevel>0) |
|
| 732 | + { |
|
| 733 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml); |
|
| 734 | + } |
|
| 609 | 735 | $AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml; |
| 610 | 736 | $isreply = true; |
| 611 | 737 | } |
@@ -614,8 +740,12 @@ discard block |
||
| 614 | 740 | // if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain |
| 615 | 741 | $bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display'); |
| 616 | 742 | $bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false); |
| 617 | - if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) { |
|
| 618 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF); |
|
| 743 | + if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) |
|
| 744 | + { |
|
| 745 | + if ($this->debugLevel>0) |
|
| 746 | + { |
|
| 747 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF); |
|
| 748 | + } |
|
| 619 | 749 | $Body = $Body."\r\n".$bodyBUFF.$sigTextPlain; |
| 620 | 750 | $isreply = true; |
| 621 | 751 | } |
@@ -623,7 +753,10 @@ discard block |
||
| 623 | 753 | { |
| 624 | 754 | $isreply = true; |
| 625 | 755 | $AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml; |
| 626 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody); |
|
| 756 | + if ($this->debugLevel>0) |
|
| 757 | + { |
|
| 758 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody); |
|
| 759 | + } |
|
| 627 | 760 | } |
| 628 | 761 | } |
| 629 | 762 | |
@@ -637,11 +770,17 @@ discard block |
||
| 637 | 770 | (isset($smartdata->replacemime) && $smartdata->replacemime == false))) |
| 638 | 771 | { |
| 639 | 772 | //force the default for the forwarding -> asmail |
| 640 | - if (is_array($preferencesArray)) { |
|
| 773 | + if (is_array($preferencesArray)) |
|
| 774 | + { |
|
| 641 | 775 | if (!array_key_exists('message_forwarding',$preferencesArray) |
| 642 | 776 | || !isset($preferencesArray['message_forwarding']) |
| 643 | - || empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail'; |
|
| 644 | - } else { |
|
| 777 | + || empty($preferencesArray['message_forwarding'])) |
|
| 778 | + { |
|
| 779 | + $preferencesArray['message_forwarding'] = 'asmail'; |
|
| 780 | + } |
|
| 781 | + } |
|
| 782 | + else |
|
| 783 | + { |
|
| 645 | 784 | $preferencesArray['message_forwarding'] = 'asmail'; |
| 646 | 785 | } |
| 647 | 786 | // construct the uid of the message out of the itemid - seems to be the uid, no construction needed |
@@ -673,27 +812,44 @@ discard block |
||
| 673 | 812 | $this->mail->reopen($folder); |
| 674 | 813 | $bodyStruct = $this->mail->getMessageBody($uid, 'html_only'); |
| 675 | 814 | $bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false); |
| 676 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml); |
|
| 677 | - if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) { |
|
| 815 | + if ($this->debugLevel>0) |
|
| 816 | + { |
|
| 817 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml); |
|
| 818 | + } |
|
| 819 | + if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) |
|
| 820 | + { |
|
| 678 | 821 | // may be html |
| 679 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml); |
|
| 822 | + if ($this->debugLevel>0) |
|
| 823 | + { |
|
| 824 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml); |
|
| 825 | + } |
|
| 680 | 826 | $AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml; |
| 681 | 827 | $isforward = true; |
| 682 | 828 | } |
| 683 | 829 | // plain text Message part |
| 684 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:'); |
|
| 830 | + if ($this->debugLevel>0) |
|
| 831 | + { |
|
| 832 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:'); |
|
| 833 | + } |
|
| 685 | 834 | // if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain |
| 686 | 835 | $bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display'); |
| 687 | 836 | $bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false); |
| 688 | - if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) { |
|
| 689 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF); |
|
| 837 | + if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) |
|
| 838 | + { |
|
| 839 | + if ($this->debugLevel>0) |
|
| 840 | + { |
|
| 841 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF); |
|
| 842 | + } |
|
| 690 | 843 | $Body = $Body."\r\n".$bodyBUFF.$sigTextPlain; |
| 691 | 844 | $isforward = true; |
| 692 | 845 | } |
| 693 | 846 | if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody)) |
| 694 | 847 | { |
| 695 | 848 | $AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml; |
| 696 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody); |
|
| 849 | + if ($this->debugLevel>0) |
|
| 850 | + { |
|
| 851 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody); |
|
| 852 | + } |
|
| 697 | 853 | $isforward = true; |
| 698 | 854 | } |
| 699 | 855 | // get all the attachments and add them too. |
@@ -706,7 +862,10 @@ discard block |
||
| 706 | 862 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments)); |
| 707 | 863 | foreach((array)$attachments as $key => $attachment) |
| 708 | 864 | { |
| 709 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment)); |
|
| 865 | + if ($this->debugLevel>0) |
|
| 866 | + { |
|
| 867 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment)); |
|
| 868 | + } |
|
| 710 | 869 | $attachmentNames .= $attachment['name']."\n"; |
| 711 | 870 | $attachmentData = $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder); |
| 712 | 871 | /*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']); |
@@ -725,20 +884,29 @@ discard block |
||
| 725 | 884 | // now set the body |
| 726 | 885 | if ($AltBody && ($html_body = $mailObject->findBody('html'))) |
| 727 | 886 | { |
| 728 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody); |
|
| 887 | + if ($this->debugLevel>1) |
|
| 888 | + { |
|
| 889 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody); |
|
| 890 | + } |
|
| 729 | 891 | //error_log(__METHOD__.__LINE__.' html:'.$AltBody); |
| 730 | 892 | $html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); |
| 731 | 893 | } |
| 732 | 894 | if ($Body && ($text_body = $mailObject->findBody('plain'))) |
| 733 | 895 | { |
| 734 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body); |
|
| 896 | + if ($this->debugLevel>1) |
|
| 897 | + { |
|
| 898 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body); |
|
| 899 | + } |
|
| 735 | 900 | //error_log(__METHOD__.__LINE__.' text:'.$Body); |
| 736 | 901 | $text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING)); |
| 737 | 902 | } |
| 738 | 903 | //advanced debugging |
| 739 | 904 | // Horde SMTP Class uses utf-8 by default. |
| 740 | 905 | //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1)); |
| 741 | - if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject)); |
|
| 906 | + if ($this->debugLevel>2) |
|
| 907 | + { |
|
| 908 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject)); |
|
| 909 | + } |
|
| 742 | 910 | |
| 743 | 911 | // set a higher timeout for big messages |
| 744 | 912 | @set_time_limit(120); |
@@ -765,7 +933,9 @@ discard block |
||
| 765 | 933 | if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder)) |
| 766 | 934 | { |
| 767 | 935 | $this->mail->deleteMessages(array($uid),$folder); |
| 768 | - } else { |
|
| 936 | + } |
|
| 937 | + else |
|
| 938 | + { |
|
| 769 | 939 | $this->mail->flagMessages("answered", array($uid),$folder); |
| 770 | 940 | if ($smartdata_task== "forward") |
| 771 | 941 | { |
@@ -779,7 +949,8 @@ discard block |
||
| 779 | 949 | { |
| 780 | 950 | $asf = false; |
| 781 | 951 | $sentFolder = $this->mail->getSentFolder(); |
| 782 | - if ($this->_sentID) { |
|
| 952 | + if ($this->_sentID) |
|
| 953 | + { |
|
| 783 | 954 | $folderArray[] = $this->_sentID; |
| 784 | 955 | } |
| 785 | 956 | else if(isset($sentFolder) && $sentFolder != 'none') |
@@ -793,28 +964,41 @@ discard block |
||
| 793 | 964 | // we dont try guessing |
| 794 | 965 | $asf = true; |
| 795 | 966 | } |
| 796 | - if (count($folderArray) > 0) { |
|
| 797 | - foreach((array)$bccMailAddr as $address) { |
|
| 798 | - foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) { |
|
| 967 | + if (count($folderArray) > 0) |
|
| 968 | + { |
|
| 969 | + foreach((array)$bccMailAddr as $address) |
|
| 970 | + { |
|
| 971 | + foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) |
|
| 972 | + { |
|
| 799 | 973 | $emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''); |
| 800 | 974 | $mailAddr[] = array($emailAddress, $addressObject->personal); |
| 801 | 975 | } |
| 802 | 976 | } |
| 803 | 977 | //$BCCmail=''; |
| 804 | - if (count($mailAddr)>0) $mailObject->forceBccHeader(); |
|
| 978 | + if (count($mailAddr)>0) |
|
| 979 | + { |
|
| 980 | + $mailObject->forceBccHeader(); |
|
| 981 | + } |
|
| 805 | 982 | //$BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr); |
| 806 | - foreach($folderArray as $folderName) { |
|
| 807 | - if($this->mail->isSentFolder($folderName)) { |
|
| 983 | + foreach($folderArray as $folderName) |
|
| 984 | + { |
|
| 985 | + if($this->mail->isSentFolder($folderName)) |
|
| 986 | + { |
|
| 808 | 987 | $flags = '\\Seen'; |
| 809 | - } elseif($this->mail->isDraftFolder($folderName)) { |
|
| 988 | + } |
|
| 989 | + elseif($this->mail->isDraftFolder($folderName)) |
|
| 990 | + { |
|
| 810 | 991 | $flags = '\\Draft'; |
| 811 | - } else { |
|
| 992 | + } |
|
| 993 | + else |
|
| 994 | + { |
|
| 812 | 995 | $flags = ''; |
| 813 | 996 | } |
| 814 | 997 | $asf = true; |
| 815 | 998 | //ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer)); |
| 816 | 999 | $this->mail->openConnection(self::$profileID,false); |
| 817 | - if ($this->mail->folderExists($folderName)) { |
|
| 1000 | + if ($this->mail->folderExists($folderName)) |
|
| 1001 | + { |
|
| 818 | 1002 | try |
| 819 | 1003 | { |
| 820 | 1004 | $this->mail->appendMessage($folderName,$mailObject->getRaw(), null, |
@@ -872,17 +1056,26 @@ discard block |
||
| 872 | 1056 | $bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */ |
| 873 | 1057 | |
| 874 | 1058 | // fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0 |
| 875 | - if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]); |
|
| 1059 | + if (!$mimesupport && ($key = array_search('4', $bodypreference))) |
|
| 1060 | + { |
|
| 1061 | + unset($bodypreference[$key]); |
|
| 1062 | + } |
|
| 876 | 1063 | |
| 877 | 1064 | //$this->debugLevel=4; |
| 878 | - if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true); |
|
| 1065 | + if (!isset($this->mail)) |
|
| 1066 | + { |
|
| 1067 | + $this->mail = Mail::getInstance(false,self::$profileID,true,false,true); |
|
| 1068 | + } |
|
| 879 | 1069 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference)); |
| 880 | 1070 | $account = $_folderName = $xid = null; |
| 881 | 1071 | $this->splitID($folderid,$account,$_folderName,$xid); |
| 882 | 1072 | $this->mail->reopen($_folderName); |
| 883 | 1073 | $messages = $this->fetchMessages($folderid, NULL, $id, true); // true: return all headers |
| 884 | 1074 | $headers = $messages[$id]; |
| 885 | - if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers)); |
|
| 1075 | + if ($this->debugLevel>3) |
|
| 1076 | + { |
|
| 1077 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers)); |
|
| 1078 | + } |
|
| 886 | 1079 | // StatMessage should reopen the folder in question, so we dont need folderids in the following statements. |
| 887 | 1080 | if ($headers) |
| 888 | 1081 | { |
@@ -892,16 +1085,25 @@ discard block |
||
| 892 | 1085 | //$rawHeaders = $this->mail->getMessageRawHeader($id); |
| 893 | 1086 | // simple style |
| 894 | 1087 | // start AS12 Stuff (bodypreference === false) case = old behaviour |
| 895 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers)); |
|
| 1088 | + if ($this->debugLevel>0) |
|
| 1089 | + { |
|
| 1090 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers)); |
|
| 1091 | + } |
|
| 896 | 1092 | |
| 897 | - if ($bodypreference === false) { |
|
| 1093 | + if ($bodypreference === false) |
|
| 1094 | + { |
|
| 898 | 1095 | $bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName); |
| 899 | 1096 | $raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false); |
| 900 | 1097 | //$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body)); |
| 901 | - if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part |
|
| 1098 | + if (stripos($raw_body,'<style')!==false) |
|
| 1099 | + { |
|
| 1100 | + $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); |
|
| 1101 | + } |
|
| 1102 | + // in case there is only a html part |
|
| 902 | 1103 | // remove all other html |
| 903 | 1104 | $body = strip_tags($raw_body); |
| 904 | - if(strlen($body) > $truncsize) { |
|
| 1105 | + if(strlen($body) > $truncsize) |
|
| 1106 | + { |
|
| 905 | 1107 | $body = Utils::Utf8_truncate($body, $truncsize); |
| 906 | 1108 | $output->bodytruncated = 1; |
| 907 | 1109 | } |
@@ -916,7 +1118,8 @@ discard block |
||
| 916 | 1118 | { |
| 917 | 1119 | //Select body type preference |
| 918 | 1120 | $bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN; |
| 919 | - if ($bodypreference !== false) { |
|
| 1121 | + if ($bodypreference !== false) |
|
| 1122 | + { |
|
| 920 | 1123 | // bodypreference can occur multiple times |
| 921 | 1124 | // usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference); |
| 922 | 1125 | $bpReturnType = Utils::GetBodyPreferenceBestMatch($bodypreference); |
@@ -950,25 +1153,49 @@ discard block |
||
| 950 | 1153 | // fetch the body (try to gather data only once) |
| 951 | 1154 | $css =''; |
| 952 | 1155 | $bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName); |
| 953 | - if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct)); |
|
| 1156 | + if ($this->debugLevel>2) |
|
| 1157 | + { |
|
| 1158 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct)); |
|
| 1159 | + } |
|
| 954 | 1160 | $body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false); |
| 955 | - if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body); |
|
| 956 | - if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) { |
|
| 1161 | + if ($this->debugLevel>3) |
|
| 1162 | + { |
|
| 1163 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body); |
|
| 1164 | + } |
|
| 1165 | + if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) |
|
| 1166 | + { |
|
| 957 | 1167 | // may be html |
| 958 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)'); |
|
| 1168 | + if ($this->debugLevel>0) |
|
| 1169 | + { |
|
| 1170 | + ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)'); |
|
| 1171 | + } |
|
| 959 | 1172 | $css = $this->mail->getStyles($bodyStruct); |
| 960 | 1173 | $output->nativebodytype=2; |
| 961 | - } else { |
|
| 1174 | + } |
|
| 1175 | + else |
|
| 1176 | + { |
|
| 962 | 1177 | // plain text Message |
| 963 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)'); |
|
| 1178 | + if ($this->debugLevel>0) |
|
| 1179 | + { |
|
| 1180 | + ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)'); |
|
| 1181 | + } |
|
| 964 | 1182 | $output->nativebodytype=1; |
| 965 | 1183 | $bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text'); |
| 966 | - if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct)); |
|
| 1184 | + if ($this->debugLevel>3) |
|
| 1185 | + { |
|
| 1186 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct)); |
|
| 1187 | + } |
|
| 967 | 1188 | $body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false); |
| 968 | - if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body); |
|
| 1189 | + if ($this->debugLevel>3) |
|
| 1190 | + { |
|
| 1191 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body); |
|
| 1192 | + } |
|
| 969 | 1193 | } |
| 970 | 1194 | // whatever format decode (using the correct encoding) |
| 971 | - if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body); |
|
| 1195 | + if ($this->debugLevel>3) |
|
| 1196 | + { |
|
| 1197 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body); |
|
| 1198 | + } |
|
| 972 | 1199 | //$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body)); |
| 973 | 1200 | // prepare plaintextbody |
| 974 | 1201 | $plainBody=''; |
@@ -989,12 +1216,18 @@ discard block |
||
| 989 | 1216 | // remove all other html |
| 990 | 1217 | $plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody); |
| 991 | 1218 | $plainBody = strip_tags($plainBody); |
| 992 | - if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody); |
|
| 1219 | + if ($this->debugLevel>3 && $output->nativebodytype==1) |
|
| 1220 | + { |
|
| 1221 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody); |
|
| 1222 | + } |
|
| 993 | 1223 | //$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that? |
| 994 | 1224 | |
| 995 | - if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML |
|
| 1225 | + if ($bpReturnType==2) |
|
| 1226 | + { |
|
| 1227 | + //SYNC_BODYPREFERENCE_HTML |
|
| 996 | 1228 | { |
| 997 | 1229 | if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2"); |
| 1230 | + } |
|
| 998 | 1231 | // Send HTML if requested and native type was html |
| 999 | 1232 | $output->asbody->type = 2; |
| 1000 | 1233 | $htmlbody = '<html>'. |
@@ -1006,7 +1239,10 @@ discard block |
||
| 1006 | 1239 | '<body>'; |
| 1007 | 1240 | if ($output->nativebodytype==2) |
| 1008 | 1241 | { |
| 1009 | - if ($css) Api\Mail\Html::replaceTagsCompletley($body,'style'); |
|
| 1242 | + if ($css) |
|
| 1243 | + { |
|
| 1244 | + Api\Mail\Html::replaceTagsCompletley($body,'style'); |
|
| 1245 | + } |
|
| 1010 | 1246 | // as we fetch html, and body is HTML, we may not need to handle this |
| 1011 | 1247 | $htmlbody .= $body; |
| 1012 | 1248 | } |
@@ -1031,7 +1267,10 @@ discard block |
||
| 1031 | 1267 | else |
| 1032 | 1268 | { |
| 1033 | 1269 | // Send Plaintext as Fallback or if original body is plainttext |
| 1034 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody); |
|
| 1270 | + if ($this->debugLevel>0) |
|
| 1271 | + { |
|
| 1272 | + ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody); |
|
| 1273 | + } |
|
| 1035 | 1274 | /* we use plainBody (set above) instead |
| 1036 | 1275 | $bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display'); |
| 1037 | 1276 | $plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct); |
@@ -1068,7 +1307,9 @@ discard block |
||
| 1068 | 1307 | { |
| 1069 | 1308 | $output->flag->flagstatus = 2; |
| 1070 | 1309 | //$output->flag->flagtype = "Flag for Follow up"; |
| 1071 | - } else { |
|
| 1310 | + } |
|
| 1311 | + else |
|
| 1312 | + { |
|
| 1072 | 1313 | $output->flag->flagstatus = 0; |
| 1073 | 1314 | } |
| 1074 | 1315 | if ($headers['answered']) |
@@ -1084,10 +1325,20 @@ discard block |
||
| 1084 | 1325 | ($headers['priority'] < 3 ? 2 : 1) ; |
| 1085 | 1326 | $output->datereceived = $this->mail->_strtotime($headers['date'],'ts',true); |
| 1086 | 1327 | $output->to = $headers['to_address']; |
| 1087 | - if ($headers['to']) $output->displayto = $headers['to_address']; //$headers['FETCHED_HEADER']['to_name'] |
|
| 1328 | + if ($headers['to']) |
|
| 1329 | + { |
|
| 1330 | + $output->displayto = $headers['to_address']; |
|
| 1331 | + } |
|
| 1332 | + //$headers['FETCHED_HEADER']['to_name'] |
|
| 1088 | 1333 | $output->from = $headers['sender_address']; |
| 1089 | - if (isset($headers['cc_addresses']) && $headers['cc_addresses']) $output->cc = $headers['cc_addresses']; |
|
| 1090 | - if (isset($headers['reply_to_address']) && $headers['reply_to_address']) $output->reply_to = $headers['reply_to_address']; |
|
| 1334 | + if (isset($headers['cc_addresses']) && $headers['cc_addresses']) |
|
| 1335 | + { |
|
| 1336 | + $output->cc = $headers['cc_addresses']; |
|
| 1337 | + } |
|
| 1338 | + if (isset($headers['reply_to_address']) && $headers['reply_to_address']) |
|
| 1339 | + { |
|
| 1340 | + $output->reply_to = $headers['reply_to_address']; |
|
| 1341 | + } |
|
| 1091 | 1342 | |
| 1092 | 1343 | $output->messageclass = "IPM.Note"; |
| 1093 | 1344 | if (stripos($headers['mimetype'],'multipart')!== false && |
@@ -1095,7 +1346,8 @@ discard block |
||
| 1095 | 1346 | { |
| 1096 | 1347 | $output->messageclass = "IPM.Note.SMIME.MultipartSigned"; |
| 1097 | 1348 | } |
| 1098 | - if (Request::GetProtocolVersion() >= 12.0) { |
|
| 1349 | + if (Request::GetProtocolVersion() >= 12.0) |
|
| 1350 | + { |
|
| 1099 | 1351 | $output->contentclass = "urn:content-classes:message"; |
| 1100 | 1352 | } |
| 1101 | 1353 | |
@@ -1108,7 +1360,10 @@ discard block |
||
| 1108 | 1360 | //error_log(__METHOD__.__LINE__.array2string($attachments)); |
| 1109 | 1361 | foreach ($attachments as $key => $attach) |
| 1110 | 1362 | { |
| 1111 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach)); |
|
| 1363 | + if ($this->debugLevel>0) |
|
| 1364 | + { |
|
| 1365 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach)); |
|
| 1366 | + } |
|
| 1112 | 1367 | |
| 1113 | 1368 | // pass meeting requests to calendar plugin |
| 1114 | 1369 | if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' && |
@@ -1125,17 +1380,24 @@ discard block |
||
| 1125 | 1380 | unset($attachment); |
| 1126 | 1381 | continue; // do NOT add attachment as attachment |
| 1127 | 1382 | } |
| 1128 | - if (Request::GetProtocolVersion() >= 12.0) { |
|
| 1383 | + if (Request::GetProtocolVersion() >= 12.0) |
|
| 1384 | + { |
|
| 1129 | 1385 | $attachment = new SyncBaseAttachment(); |
| 1130 | 1386 | if (!isset($output->asattachments) || !is_array($output->asattachments)) |
| 1131 | - $output->asattachments = array(); |
|
| 1387 | + { |
|
| 1388 | + $output->asattachments = array(); |
|
| 1389 | + } |
|
| 1132 | 1390 | $attachment->estimatedDataSize = $attach['size']; |
| 1133 | 1391 | $attachment->method = 1; |
| 1134 | 1392 | $attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID']; |
| 1135 | - } else { |
|
| 1393 | + } |
|
| 1394 | + else |
|
| 1395 | + { |
|
| 1136 | 1396 | $attachment = new SyncAttachment(); |
| 1137 | 1397 | if (!isset($output->attachments) || !is_array($output->attachments)) |
| 1138 | - $output->attachments = array(); |
|
| 1398 | + { |
|
| 1399 | + $output->attachments = array(); |
|
| 1400 | + } |
|
| 1139 | 1401 | $attachment->attsize = $attach['size']; |
| 1140 | 1402 | $attachment->attmethod = 1; |
| 1141 | 1403 | $attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key; |
@@ -1152,10 +1414,13 @@ discard block |
||
| 1152 | 1414 | { |
| 1153 | 1415 | $attachment->isinline = true; |
| 1154 | 1416 | } |
| 1155 | - if (Request::GetProtocolVersion() >= 12.0) { |
|
| 1417 | + if (Request::GetProtocolVersion() >= 12.0) |
|
| 1418 | + { |
|
| 1156 | 1419 | $attachment->method=1; |
| 1157 | 1420 | $attachment->contentid= str_replace(array("<",">"), "",$attach['cid']); |
| 1158 | - } else { |
|
| 1421 | + } |
|
| 1422 | + else |
|
| 1423 | + { |
|
| 1159 | 1424 | $attachment->attmethod=6; |
| 1160 | 1425 | $attachment->attoid = str_replace(array("<",">"), "",$attach['cid']); |
| 1161 | 1426 | } |
@@ -1163,9 +1428,12 @@ discard block |
||
| 1163 | 1428 | $attachment->contenttype = trim($attach['mimeType']); |
| 1164 | 1429 | // ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-type']."' ".$attachment->contentid); |
| 1165 | 1430 | } |
| 1166 | - if (Request::GetProtocolVersion() >= 12.0) { |
|
| 1431 | + if (Request::GetProtocolVersion() >= 12.0) |
|
| 1432 | + { |
|
| 1167 | 1433 | array_push($output->asattachments, $attachment); |
| 1168 | - } else { |
|
| 1434 | + } |
|
| 1435 | + else |
|
| 1436 | + { |
|
| 1169 | 1437 | array_push($output->attachments, $attachment); |
| 1170 | 1438 | } |
| 1171 | 1439 | unset($attachment); |
@@ -1178,8 +1446,11 @@ discard block |
||
| 1178 | 1446 | // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx |
| 1179 | 1447 | $output->internetcpid = INTERNET_CPID_UTF8; |
| 1180 | 1448 | |
| 1181 | - if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output)); |
|
| 1182 | -//$this->debugLevel=0; |
|
| 1449 | + if ($this->debugLevel>3) |
|
| 1450 | + { |
|
| 1451 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output)); |
|
| 1452 | + } |
|
| 1453 | + //$this->debugLevel=0; |
|
| 1183 | 1454 | return $output; |
| 1184 | 1455 | } |
| 1185 | 1456 | //$this->debugLevel=0; |
@@ -1238,7 +1509,8 @@ discard block |
||
| 1238 | 1509 | * @param string $attname - should contain (folder)id |
| 1239 | 1510 | * @return SyncItemOperationsAttachment-object |
| 1240 | 1511 | */ |
| 1241 | - function GetAttachmentData($fid,$attname) { |
|
| 1512 | + function GetAttachmentData($fid,$attname) |
|
| 1513 | + { |
|
| 1242 | 1514 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')"); |
| 1243 | 1515 | return $this->_GetAttachmentData($fid,$attname); |
| 1244 | 1516 | } |
@@ -1253,7 +1525,8 @@ discard block |
||
| 1253 | 1525 | * @param string $attname - should contain (folder)id |
| 1254 | 1526 | * @return SyncItemOperationsAttachment-object |
| 1255 | 1527 | */ |
| 1256 | - function ItemOperationsGetAttachmentData($fid,$attname) { |
|
| 1528 | + function ItemOperationsGetAttachmentData($fid,$attname) |
|
| 1529 | + { |
|
| 1257 | 1530 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')"); |
| 1258 | 1531 | return $this->_GetAttachmentData($fid,$attname); |
| 1259 | 1532 | } |
@@ -1275,7 +1548,10 @@ discard block |
||
| 1275 | 1548 | |
| 1276 | 1549 | $this->splitID($folderid, $account, $folder); |
| 1277 | 1550 | |
| 1278 | - if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true); |
|
| 1551 | + if (!isset($this->mail)) |
|
| 1552 | + { |
|
| 1553 | + $this->mail = Mail::getInstance(false,self::$profileID,true,false,true); |
|
| 1554 | + } |
|
| 1279 | 1555 | |
| 1280 | 1556 | $this->mail->reopen($folder); |
| 1281 | 1557 | $attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder); |
@@ -1284,7 +1560,9 @@ discard block |
||
| 1284 | 1560 | $SIOattachment->data = $attachment['attachment']; |
| 1285 | 1561 | //ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']); |
| 1286 | 1562 | if (isset($attachment['type']) ) |
| 1287 | - $SIOattachment->contenttype = $attachment['type']; |
|
| 1563 | + { |
|
| 1564 | + $SIOattachment->contenttype = $attachment['type']; |
|
| 1565 | + } |
|
| 1288 | 1566 | |
| 1289 | 1567 | unset($attachment); |
| 1290 | 1568 | |
@@ -1330,11 +1608,15 @@ discard block |
||
| 1330 | 1608 | //unset($folderid, $id, $message, $contentParameters); |
| 1331 | 1609 | $account = $folder = null; |
| 1332 | 1610 | $this->splitID($folderid, $account, $folder); |
| 1333 | - if (isset($message->flag)) { |
|
| 1334 | - if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) { |
|
| 1611 | + if (isset($message->flag)) |
|
| 1612 | + { |
|
| 1613 | + if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) |
|
| 1614 | + { |
|
| 1335 | 1615 | $rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder); |
| 1336 | 1616 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv); |
| 1337 | - } else { |
|
| 1617 | + } |
|
| 1618 | + else |
|
| 1619 | + { |
|
| 1338 | 1620 | $rv = $this->mail->flagMessages("unflagged", $id,$folder); |
| 1339 | 1621 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv); |
| 1340 | 1622 | } |
@@ -1364,7 +1646,10 @@ discard block |
||
| 1364 | 1646 | $this->splitID($folderid, $account, $srcFolder); |
| 1365 | 1647 | $this->splitID($newfolderid, $account, $destFolder); |
| 1366 | 1648 | ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder' id: '$id' DestFolder: '$destFolder' )"); |
| 1367 | - if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true); |
|
| 1649 | + if (!isset($this->mail)) |
|
| 1650 | + { |
|
| 1651 | + $this->mail = Mail::getInstance(false,self::$profileID,true,false,true); |
|
| 1652 | + } |
|
| 1368 | 1653 | $this->mail->reopen($destFolder); |
| 1369 | 1654 | $status = $this->mail->getFolderStatus($destFolder); |
| 1370 | 1655 | $uidNext = $status['uidnext']; |
@@ -1396,7 +1681,10 @@ discard block |
||
| 1396 | 1681 | $maximumSyncRangeInDays = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-maximumSyncRange']; |
| 1397 | 1682 | } |
| 1398 | 1683 | $cutoffdate = (is_numeric($maximumSyncRangeInDays) ? Api\DateTime::to('now','ts')-(3600*24*$maximumSyncRangeInDays):null); |
| 1399 | - if (is_numeric($maximumSyncRangeInDays)) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate)); |
|
| 1684 | + if (is_numeric($maximumSyncRangeInDays)) |
|
| 1685 | + { |
|
| 1686 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate)); |
|
| 1687 | + } |
|
| 1400 | 1688 | } |
| 1401 | 1689 | return $this->fetchMessages($folderid, $cutoffdate); |
| 1402 | 1690 | } |
@@ -1418,7 +1706,10 @@ discard block |
||
| 1418 | 1706 | { |
| 1419 | 1707 | static $headers = array(); |
| 1420 | 1708 | |
| 1421 | - if ($this->debugLevel>1) $gstarttime = microtime (true); |
|
| 1709 | + if ($this->debugLevel>1) |
|
| 1710 | + { |
|
| 1711 | + $gstarttime = microtime (true); |
|
| 1712 | + } |
|
| 1422 | 1713 | //ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__); |
| 1423 | 1714 | $rv_messages = array(); |
| 1424 | 1715 | // if the message is still available within the class, we use it instead of fetching it again |
@@ -1431,7 +1722,10 @@ discard block |
||
| 1431 | 1722 | { |
| 1432 | 1723 | $headers = array(); // clear cache to not use too much memory |
| 1433 | 1724 | |
| 1434 | - if ($this->debugLevel>1) $starttime = microtime (true); |
|
| 1725 | + if ($this->debugLevel>1) |
|
| 1726 | + { |
|
| 1727 | + $starttime = microtime (true); |
|
| 1728 | + } |
|
| 1435 | 1729 | $this->_connect($this->account); |
| 1436 | 1730 | if ($this->debugLevel>1) |
| 1437 | 1731 | { |
@@ -1440,8 +1734,14 @@ discard block |
||
| 1440 | 1734 | } |
| 1441 | 1735 | $messagelist = $_filter = array(); |
| 1442 | 1736 | // if not connected, any further action must fail |
| 1443 | - if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate)); |
|
| 1444 | - if ($this->debugLevel>1) $starttime = microtime (true); |
|
| 1737 | + if (!empty($cutoffdate)) |
|
| 1738 | + { |
|
| 1739 | + $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate)); |
|
| 1740 | + } |
|
| 1741 | + if ($this->debugLevel>1) |
|
| 1742 | + { |
|
| 1743 | + $starttime = microtime (true); |
|
| 1744 | + } |
|
| 1445 | 1745 | $account = $_folderName = $id = null; |
| 1446 | 1746 | $this->splitID($folderid,$account,$_folderName,$id); |
| 1447 | 1747 | if ($this->debugLevel>1) |
@@ -1449,8 +1749,14 @@ discard block |
||
| 1449 | 1749 | $endtime = microtime(true) - $starttime; |
| 1450 | 1750 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid); |
| 1451 | 1751 | } |
| 1452 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id); |
|
| 1453 | - if ($this->debugLevel>1) $starttime = microtime (true); |
|
| 1752 | + if ($this->debugLevel>1) |
|
| 1753 | + { |
|
| 1754 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id); |
|
| 1755 | + } |
|
| 1756 | + if ($this->debugLevel>1) |
|
| 1757 | + { |
|
| 1758 | + $starttime = microtime (true); |
|
| 1759 | + } |
|
| 1454 | 1760 | $_numberOfMessages = (empty($cutoffdate)?250:99999); |
| 1455 | 1761 | $rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id); |
| 1456 | 1762 | if ($this->debugLevel>1) |
@@ -1459,27 +1765,56 @@ discard block |
||
| 1459 | 1765 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName); |
| 1460 | 1766 | } |
| 1461 | 1767 | } |
| 1462 | - if ($_id == NULL && $this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header'])); |
|
| 1768 | + if ($_id == NULL && $this->debugLevel>1) |
|
| 1769 | + { |
|
| 1770 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header'])); |
|
| 1771 | + } |
|
| 1463 | 1772 | //ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages)); |
| 1464 | 1773 | $messagelist = array(); |
| 1465 | - if (!isset($rv_messages['header'])||empty($rv_messages['header'])) return $messagelist; |
|
| 1774 | + if (!isset($rv_messages['header'])||empty($rv_messages['header'])) |
|
| 1775 | + { |
|
| 1776 | + return $messagelist; |
|
| 1777 | + } |
|
| 1466 | 1778 | //if ($_returnModHash) $messageFolderHash = array(); |
| 1467 | 1779 | foreach ((array)$rv_messages['header'] as $k => $vars) |
| 1468 | 1780 | { |
| 1469 | - if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']); |
|
| 1781 | + if ($this->debugLevel>3) |
|
| 1782 | + { |
|
| 1783 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']); |
|
| 1784 | + } |
|
| 1470 | 1785 | $headers[$vars['uid']] = $vars; |
| 1471 | - if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars)); |
|
| 1472 | - if (!empty($vars['deleted'])) continue; // cut of deleted messages |
|
| 1473 | - if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it |
|
| 1474 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']); |
|
| 1786 | + if ($this->debugLevel>3) |
|
| 1787 | + { |
|
| 1788 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars)); |
|
| 1789 | + } |
|
| 1790 | + if (!empty($vars['deleted'])) |
|
| 1791 | + { |
|
| 1792 | + continue; |
|
| 1793 | + } |
|
| 1794 | + // cut of deleted messages |
|
| 1795 | + if ($cutoffdate && $vars['date'] < $cutoffdate) |
|
| 1796 | + { |
|
| 1797 | + continue; |
|
| 1798 | + } |
|
| 1799 | + // message is out of range for cutoffdate, ignore it |
|
| 1800 | + if ($this->debugLevel>0) |
|
| 1801 | + { |
|
| 1802 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']); |
|
| 1803 | + } |
|
| 1475 | 1804 | $mess = $return_all_headers ? $vars : array(); |
| 1476 | 1805 | $mess["mod"] = self::doFlagsMod($vars).$vars['date']; |
| 1477 | 1806 | $mess["id"] = $vars['uid']; |
| 1478 | 1807 | // 'seen' aka 'read' is the only flag we want to know about |
| 1479 | 1808 | $mess["flags"] = 0; |
| 1480 | 1809 | // outlook supports additional flags, set them to 0 |
| 1481 | - if($vars["seen"]) $mess["flags"] = 1; |
|
| 1482 | - if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess)); |
|
| 1810 | + if($vars["seen"]) |
|
| 1811 | + { |
|
| 1812 | + $mess["flags"] = 1; |
|
| 1813 | + } |
|
| 1814 | + if ($this->debugLevel>3) |
|
| 1815 | + { |
|
| 1816 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess)); |
|
| 1817 | + } |
|
| 1483 | 1818 | $messagelist[$vars['uid']] = $mess; |
| 1484 | 1819 | unset($mess); |
| 1485 | 1820 | } |
@@ -1504,9 +1839,18 @@ discard block |
||
| 1504 | 1839 | static function doFlagsMod($headerFlags) |
| 1505 | 1840 | { |
| 1506 | 1841 | $flags = 'nnn'; |
| 1507 | - if ($headerFlags['flagged']) $flags[0] = 'f'; |
|
| 1508 | - if ($headerFlags['answered']) $flags[1] = 'a'; |
|
| 1509 | - if ($headerFlags['forwarded']) $flags[2] = 'f'; |
|
| 1842 | + if ($headerFlags['flagged']) |
|
| 1843 | + { |
|
| 1844 | + $flags[0] = 'f'; |
|
| 1845 | + } |
|
| 1846 | + if ($headerFlags['answered']) |
|
| 1847 | + { |
|
| 1848 | + $flags[1] = 'a'; |
|
| 1849 | + } |
|
| 1850 | + if ($headerFlags['forwarded']) |
|
| 1851 | + { |
|
| 1852 | + $flags[2] = 'f'; |
|
| 1853 | + } |
|
| 1510 | 1854 | //ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.'('.array2string($headerFlags).') returning '.array2string($flags)); |
| 1511 | 1855 | return $flags; |
| 1512 | 1856 | } |
@@ -1538,31 +1882,55 @@ discard block |
||
| 1538 | 1882 | { |
| 1539 | 1883 | //$this->debugLevel=1; |
| 1540 | 1884 | $searchquery=$_searchquery->GetDataArray(); |
| 1541 | - if (!is_array($searchquery)) return array(); |
|
| 1542 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery)); |
|
| 1885 | + if (!is_array($searchquery)) |
|
| 1886 | + { |
|
| 1887 | + return array(); |
|
| 1888 | + } |
|
| 1889 | + if ($this->debugLevel>0) |
|
| 1890 | + { |
|
| 1891 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery)); |
|
| 1892 | + } |
|
| 1543 | 1893 | |
| 1544 | - if (isset($searchquery['searchrebuildresults'])) { |
|
| 1894 | + if (isset($searchquery['searchrebuildresults'])) |
|
| 1895 | + { |
|
| 1545 | 1896 | $rebuildresults = $searchquery['searchrebuildresults']; |
| 1546 | - } else { |
|
| 1897 | + } |
|
| 1898 | + else |
|
| 1899 | + { |
|
| 1547 | 1900 | $rebuildresults = false; |
| 1548 | 1901 | } |
| 1549 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, 'RebuildResults ['.$rebuildresults.']' ); |
|
| 1902 | + if ($this->debugLevel>0) |
|
| 1903 | + { |
|
| 1904 | + ZLog::Write(LOGLEVEL_DEBUG, 'RebuildResults ['.$rebuildresults.']' ); |
|
| 1905 | + } |
|
| 1550 | 1906 | |
| 1551 | - if (isset($searchquery['deeptraversal'])) { |
|
| 1907 | + if (isset($searchquery['deeptraversal'])) |
|
| 1908 | + { |
|
| 1552 | 1909 | $deeptraversal = $searchquery['deeptraversal']; |
| 1553 | - } else { |
|
| 1910 | + } |
|
| 1911 | + else |
|
| 1912 | + { |
|
| 1554 | 1913 | $deeptraversal = false; |
| 1555 | 1914 | } |
| 1556 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, 'DeepTraversal ['.$deeptraversal.']' ); |
|
| 1915 | + if ($this->debugLevel>0) |
|
| 1916 | + { |
|
| 1917 | + ZLog::Write(LOGLEVEL_DEBUG, 'DeepTraversal ['.$deeptraversal.']' ); |
|
| 1918 | + } |
|
| 1557 | 1919 | |
| 1558 | - if (isset($searchquery['searchrange'])) { |
|
| 1920 | + if (isset($searchquery['searchrange'])) |
|
| 1921 | + { |
|
| 1559 | 1922 | $range = explode("-",$_searchquery->GetSearchRange()); |
| 1560 | 1923 | $start =$range[0] + 1; |
| 1561 | 1924 | $limit = $range[1] - $range[0] + 1; |
| 1562 | - } else { |
|
| 1925 | + } |
|
| 1926 | + else |
|
| 1927 | + { |
|
| 1563 | 1928 | $range = false; |
| 1564 | 1929 | } |
| 1565 | - if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, 'Range ['.print_r($range, true).']' ); |
|
| 1930 | + if ($this->debugLevel>0) |
|
| 1931 | + { |
|
| 1932 | + ZLog::Write(LOGLEVEL_DEBUG, 'Range ['.print_r($range, true).']' ); |
|
| 1933 | + } |
|
| 1566 | 1934 | |
| 1567 | 1935 | //foreach($searchquery['query'] as $k => $value) { |
| 1568 | 1936 | // $query = $value; |
@@ -1614,7 +1982,10 @@ discard block |
||
| 1614 | 1982 | $_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts')); |
| 1615 | 1983 | } |
| 1616 | 1984 | //$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate)); |
| 1617 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter)); |
|
| 1985 | + if ($this->debugLevel>1) |
|
| 1986 | + { |
|
| 1987 | + ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter)); |
|
| 1988 | + } |
|
| 1618 | 1989 | $rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL); |
| 1619 | 1990 | //ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages)); |
| 1620 | 1991 | $list=array(); |
@@ -1646,17 +2017,26 @@ discard block |
||
| 1646 | 2017 | private function getParentID($account,$folder) |
| 1647 | 2018 | { |
| 1648 | 2019 | $this->_connect($account); |
| 1649 | - if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false); |
|
| 2020 | + if (!isset($this->folders)) |
|
| 2021 | + { |
|
| 2022 | + $this->folders = $this->mail->getFolderObjects(true,false); |
|
| 2023 | + } |
|
| 1650 | 2024 | |
| 1651 | 2025 | $mailFolder = $this->folders[$folder]; |
| 1652 | - if (!isset($mailFolder)) return false; |
|
| 2026 | + if (!isset($mailFolder)) |
|
| 2027 | + { |
|
| 2028 | + return false; |
|
| 2029 | + } |
|
| 1653 | 2030 | $delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter()); |
| 1654 | 2031 | $parent = explode($delimiter,$folder); |
| 1655 | 2032 | array_pop($parent); |
| 1656 | 2033 | $parent = implode($delimiter,$parent); |
| 1657 | 2034 | |
| 1658 | 2035 | $id = $parent && $this->folders[$parent] ? $this->createID($account, $parent) : '0'; |
| 1659 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id"); |
|
| 2036 | + if ($this->debugLevel>1) |
|
| 2037 | + { |
|
| 2038 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id"); |
|
| 2039 | + } |
|
| 1660 | 2040 | return $id; |
| 1661 | 2041 | } |
| 1662 | 2042 | |
@@ -1670,7 +2050,10 @@ discard block |
||
| 1670 | 2050 | { |
| 1671 | 2051 | static $last_id = null; |
| 1672 | 2052 | static $folderObj = null; |
| 1673 | - if (isset($last_id) && $last_id === $id) return $folderObj; |
|
| 2053 | + if (isset($last_id) && $last_id === $id) |
|
| 2054 | + { |
|
| 2055 | + return $folderObj; |
|
| 2056 | + } |
|
| 1674 | 2057 | |
| 1675 | 2058 | try { |
| 1676 | 2059 | $account = $folder = null; |
@@ -1681,18 +2064,30 @@ discard block |
||
| 1681 | 2064 | return $folderObj=false; |
| 1682 | 2065 | } |
| 1683 | 2066 | $this->_connect($account); |
| 1684 | - if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false); |
|
| 2067 | + if (!isset($this->folders)) |
|
| 2068 | + { |
|
| 2069 | + $this->folders = $this->mail->getFolderObjects(true,false); |
|
| 2070 | + } |
|
| 1685 | 2071 | |
| 1686 | 2072 | $mailFolder = $this->folders[$folder]; |
| 1687 | - if (!isset($mailFolder)) return $folderObj=false; |
|
| 2073 | + if (!isset($mailFolder)) |
|
| 2074 | + { |
|
| 2075 | + return $folderObj=false; |
|
| 2076 | + } |
|
| 1688 | 2077 | |
| 1689 | 2078 | $folderObj = new SyncFolder(); |
| 1690 | 2079 | $folderObj->serverid = $id; |
| 1691 | 2080 | $folderObj->parentid = $this->getParentID($account,$folder); |
| 1692 | 2081 | $folderObj->displayname = $mailFolder->shortDisplayName; |
| 1693 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder"); |
|
| 2082 | + if ($this->debugLevel>1) |
|
| 2083 | + { |
|
| 2084 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder"); |
|
| 2085 | + } |
|
| 1694 | 2086 | // get folder-type |
| 1695 | - foreach($this->folders as $inbox => $mailFolder) break; |
|
| 2087 | + foreach($this->folders as $inbox => $mailFolder) |
|
| 2088 | + { |
|
| 2089 | + break; |
|
| 2090 | + } |
|
| 1696 | 2091 | if ($folder == $inbox) |
| 1697 | 2092 | { |
| 1698 | 2093 | $folderObj->type = SYNC_FOLDER_TYPE_INBOX; |
@@ -1729,7 +2124,10 @@ discard block |
||
| 1729 | 2124 | $folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL; |
| 1730 | 2125 | } |
| 1731 | 2126 | |
| 1732 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname"); |
|
| 2127 | + if ($this->debugLevel>1) |
|
| 2128 | + { |
|
| 2129 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname"); |
|
| 2130 | + } |
|
| 1733 | 2131 | return $folderObj; |
| 1734 | 2132 | } |
| 1735 | 2133 | |
@@ -1773,11 +2171,20 @@ discard block |
||
| 1773 | 2171 | { |
| 1774 | 2172 | $account = $folder = null; |
| 1775 | 2173 | $this->splitID($folderid, $account, $folder); |
| 1776 | - if (is_numeric($account)) $type = 'mail'; |
|
| 2174 | + if (is_numeric($account)) |
|
| 2175 | + { |
|
| 2176 | + $type = 'mail'; |
|
| 2177 | + } |
|
| 1777 | 2178 | |
| 1778 | - if ($type != 'mail') return false; |
|
| 2179 | + if ($type != 'mail') |
|
| 2180 | + { |
|
| 2181 | + return false; |
|
| 2182 | + } |
|
| 1779 | 2183 | |
| 1780 | - if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true); |
|
| 2184 | + if (!isset($this->mail)) |
|
| 2185 | + { |
|
| 2186 | + $this->mail = Mail::getInstance(false,self::$profileID,true,false,true); |
|
| 2187 | + } |
|
| 1781 | 2188 | |
| 1782 | 2189 | $this->mail->reopen($folder); |
| 1783 | 2190 | |
@@ -1822,7 +2229,7 @@ discard block |
||
| 1822 | 2229 | * @throws StatusException could throw specific SYNC_STATUS_* exceptions |
| 1823 | 2230 | */ |
| 1824 | 2231 | public function DeleteMessage($folderid, $id, $contentParameters) |
| 1825 | - { |
|
| 2232 | + { |
|
| 1826 | 2233 | unset($contentParameters); // not used, but required by function signature |
| 1827 | 2234 | ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid' id: '$id' )"); |
| 1828 | 2235 | /* |
@@ -1848,7 +2255,10 @@ discard block |
||
| 1848 | 2255 | $error = $e->getMessage(); |
| 1849 | 2256 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error); |
| 1850 | 2257 | // if the server thinks the message does not exist report deletion as success |
| 1851 | - if (stripos($error,'[NONEXISTENT]')!==false) return true; |
|
| 2258 | + if (stripos($error,'[NONEXISTENT]')!==false) |
|
| 2259 | + { |
|
| 2260 | + return true; |
|
| 2261 | + } |
|
| 1852 | 2262 | return false; |
| 1853 | 2263 | } |
| 1854 | 2264 | |
@@ -1881,7 +2291,7 @@ discard block |
||
| 1881 | 2291 | * @throws StatusException could throw specific SYNC_STATUS_* exceptions |
| 1882 | 2292 | */ |
| 1883 | 2293 | public function SetReadFlag($folderid, $id, $flags, $contentParameters) |
| 1884 | - { |
|
| 2294 | + { |
|
| 1885 | 2295 | unset($contentParameters); // not used, but required by function signature |
| 1886 | 2296 | // ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid' id: '$id' flags: '$flags' )"); |
| 1887 | 2297 | $account = $folder = null; |
@@ -1965,10 +2375,16 @@ discard block |
||
| 1965 | 2375 | $account = $parent_id = $app = null; |
| 1966 | 2376 | $this->splitID($id, $account, $folder, $app); |
| 1967 | 2377 | $old_hash = $this->folder2hash($account, $folder); |
| 1968 | - if ($parentid) $this->splitID($parentid, $account, $parentfolder, $app); |
|
| 2378 | + if ($parentid) |
|
| 2379 | + { |
|
| 2380 | + $this->splitID($parentid, $account, $parentfolder, $app); |
|
| 2381 | + } |
|
| 1969 | 2382 | ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."( '$id (-> $folder)','$parentid ".($parentid?'(->'.$parentfolder.')':'')."') called!"); |
| 1970 | 2383 | $ret = $this->mail->deleteFolder($folder); |
| 1971 | - if ($ret) $newHash = $this->rename_folder_hash($account, $old_hash, "##Dele#edFolder#$folder##"); |
|
| 2384 | + if ($ret) |
|
| 2385 | + { |
|
| 2386 | + $newHash = $this->rename_folder_hash($account, $old_hash, "##Dele#edFolder#$folder##"); |
|
| 2387 | + } |
|
| 1972 | 2388 | return $ret; |
| 1973 | 2389 | } |
| 1974 | 2390 | |
@@ -2013,7 +2429,10 @@ discard block |
||
| 2013 | 2429 | |
| 2014 | 2430 | $str = $this->backend->createID($account, $folder, $id); |
| 2015 | 2431 | |
| 2016 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'"); |
|
| 2432 | + if ($this->debugLevel>1) |
|
| 2433 | + { |
|
| 2434 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'"); |
|
| 2435 | + } |
|
| 2017 | 2436 | |
| 2018 | 2437 | return $str; |
| 2019 | 2438 | } |
@@ -2034,7 +2453,10 @@ discard block |
||
| 2034 | 2453 | // convert numeric folder-id back to folder name |
| 2035 | 2454 | $folder = $this->hash2folder($account,$f=$folder); |
| 2036 | 2455 | |
| 2037 | - if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$appid)"); |
|
| 2456 | + if ($this->debugLevel>1) |
|
| 2457 | + { |
|
| 2458 | + ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$appid)"); |
|
| 2459 | + } |
|
| 2038 | 2460 | } |
| 2039 | 2461 | |
| 2040 | 2462 | /** |
@@ -2053,7 +2475,10 @@ discard block |
||
| 2053 | 2475 | */ |
| 2054 | 2476 | private function folder2hash($account,$folder) |
| 2055 | 2477 | { |
| 2056 | - if(!isset($this->folderHashes)) $this->readFolderHashes(); |
|
| 2478 | + if(!isset($this->folderHashes)) |
|
| 2479 | + { |
|
| 2480 | + $this->readFolderHashes(); |
|
| 2481 | + } |
|
| 2057 | 2482 | |
| 2058 | 2483 | if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false) |
| 2059 | 2484 | { |
@@ -2076,7 +2501,10 @@ discard block |
||
| 2076 | 2501 | */ |
| 2077 | 2502 | private function hash2folder($account,$index) |
| 2078 | 2503 | { |
| 2079 | - if(!isset($this->folderHashes)) $this->readFolderHashes(); |
|
| 2504 | + if(!isset($this->folderHashes)) |
|
| 2505 | + { |
|
| 2506 | + $this->readFolderHashes(); |
|
| 2507 | + } |
|
| 2080 | 2508 | |
| 2081 | 2509 | return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null; |
| 2082 | 2510 | } |