From 6ce05919b675eafd725fbee7415e6a87818f5d6d Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 30 Mar 2021 20:34:34 +0200 Subject: [PATCH] fix PHP 8 errors shown by PHPStorm --- mail/inc/class.mail_acl.inc.php | 5 +- mail/inc/class.mail_compose.inc.php | 22 +++-- mail/inc/class.mail_hooks.inc.php | 2 +- mail/inc/class.mail_integration.inc.php | 2 +- mail/inc/class.mail_sieve.inc.php | 13 +-- mail/inc/class.mail_ui.inc.php | 103 +++++++++--------------- mail/inc/class.mail_zpush.inc.php | 8 +- 7 files changed, 59 insertions(+), 96 deletions(-) diff --git a/mail/inc/class.mail_acl.inc.php b/mail/inc/class.mail_acl.inc.php index ed4d7d5767..c858d47245 100644 --- a/mail/inc/class.mail_acl.inc.php +++ b/mail/inc/class.mail_acl.inc.php @@ -162,8 +162,9 @@ class mail_acl $n = 1; foreach ($acl as $key => $value) { - $virtuals = array_pop(array_values((array)$value)); - $rights = array_shift(array_values((array)$value)); + $parts = array_values((array)$value); + $virtuals = array_pop($parts); + $rights = array_shift($parts); foreach ($rights as $right) { diff --git a/mail/inc/class.mail_compose.inc.php b/mail/inc/class.mail_compose.inc.php index b8af3f93a1..574bcd2a62 100644 --- a/mail/inc/class.mail_compose.inc.php +++ b/mail/inc/class.mail_compose.inc.php @@ -1073,7 +1073,8 @@ class mail_compose if (($_REQUEST['mimeType']=="text" ||$_REQUEST['mimeType']=="plain") && $content['mimeType'] == 'html') { $_content['mimeType'] = $content['mimeType'] = 'plain'; - $content['body'] = $this->convertHTMLToText(str_replace(array("\n\r","\n"),' ',$content['body'])); + $html = str_replace(array("\n\r","\n"),' ',$content['body']); + $content['body'] = $this->convertHTMLToText($html); } if ($_REQUEST['mimeType']=="html" && $content['mimeType'] != 'html') { @@ -1092,7 +1093,8 @@ class mail_compose $content['mimeType'] == 'html') { $_content['mimeType'] = $content['mimeType'] = 'plain'; - $content['body'] = $this->convertHTMLToText(str_replace(array("\n\r","\n"),' ',$content['body'])); + $html = str_replace(array("\n\r","\n"),' ',$content['body']); + $content['body'] = $this->convertHTMLToText($html); } if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions']=="html" && $content['mimeType'] != 'html') @@ -1553,10 +1555,10 @@ class mail_compose case 'forward': $mode = ($_GET['mode']=='forwardinline'?'inline':'asmail'); // this fill the session data with the values from the original email - foreach ($replyIds as &$mail_id) + foreach ($replyIds as &$m_id) { - //error_log(__METHOD__.__LINE__.' ID:'.$mail_id.' Mode:'.$mode); - $hA = mail_ui::splitRowID($mail_id); + //error_log(__METHOD__.__LINE__.' ID:'.$m_id.' Mode:'.$mode); + $hA = mail_ui::splitRowID($m_id); $msgUID = $hA['msgUID']; $folder = $hA['folder']; $content = $this->getForwardData($icServer, $folder, $msgUID, $part_id, $mode); @@ -1610,13 +1612,6 @@ class mail_compose base64_encode($folder).mail_ui::$delimiter.$merged_mail_id; $content = $this->getComposeFrom($merged_mail_id, $part_id, 'composefromdraft', $_focusElement, $suppressSigOnTop, $isReply); } - else - { - $success = implode(', ',$results['success']); - $fail = implode(', ', $results['failed']); - if($success) Framework::message($success, 'success'); - Framework::window_close($fail); - } } catch (Api\Exception\WrongUserinput $e) { @@ -2116,7 +2111,8 @@ class mail_compose } } //error_log(__METHOD__.__LINE__.'->'.array2string($attachment)); - Api\Header\Content::safe($attachment['attachment'], $attachment['name'], $attachment['type'], $size=0, true, $_GET['mode'] == "save"); + $size = 0; + Api\Header\Content::safe($attachment['attachment'], $attachment['name'], $attachment['type'], $size, true, $_GET['mode'] == "save"); echo $attachment['attachment']; exit(); diff --git a/mail/inc/class.mail_hooks.inc.php b/mail/inc/class.mail_hooks.inc.php index cb4500a5bd..1ab0d1fb09 100644 --- a/mail/inc/class.mail_hooks.inc.php +++ b/mail/inc/class.mail_hooks.inc.php @@ -657,7 +657,7 @@ class mail_hooks // $_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true $headers = $bomail->getHeaders($notify_folder, 1, 999, 0, true, $_filter,null,false); if(is_array($headers['header']) && count($headers['header']) > 0) { - foreach($headers['header'] as $id=>$header) { + foreach($headers['header'] as $header) { // check if unseen mail has already been notified $headerrowid = mail_ui::generateRowID($activeProfile, $notify_folder, $header['uid'], $_prependApp=false); if(!in_array($headerrowid, $notified_mail_uidsCache[$activeProfile][$notify_folder])) { diff --git a/mail/inc/class.mail_integration.inc.php b/mail/inc/class.mail_integration.inc.php index 4147f0bff1..00ee1b500f 100644 --- a/mail/inc/class.mail_integration.inc.php +++ b/mail/inc/class.mail_integration.inc.php @@ -400,7 +400,7 @@ class mail_integration { 'html_message' => $mailcontent['html_message'], 'date' => $mailcontent['date'], 'subject' => $mailcontent['subject'], - 'entry_id' => $app_entry_id + 'entry_id' => null, ); } diff --git a/mail/inc/class.mail_sieve.inc.php b/mail/inc/class.mail_sieve.inc.php index 6964e608b0..1b08caaea4 100644 --- a/mail/inc/class.mail_sieve.inc.php +++ b/mail/inc/class.mail_sieve.inc.php @@ -278,6 +278,7 @@ class mail_sieve //$ruleID is calculated by priority from the selected rule and is an unique ID $content['ruleID'] = $ruleID = ($this->rulesByID['priority'] -1) / 2; $error = 0; + $msg = ''; switch ($button) { case 'save': @@ -1040,14 +1041,9 @@ class mail_sieve $complete .= $andor; } $complete .= "message " . $xthan . $rule['size'] . "KB'"; - $started = 1; } if (!empty($rule['field_bodytransform'])) { - if ($started) - { - $newruletext .= ", "; - } $btransform = " :raw "; $match = ' :contains'; if ($rule['bodytransform']) @@ -1063,15 +1059,9 @@ class mail_sieve $match = ':regex'; } $complete .= " body " . $btransform . $match . " \"" . $rule['field_bodytransform'] . "\""; - $started = 1; - } if ($rule['ctype']!= '0' && !empty($rule['ctype'])) { - if ($started) - { - $newruletext .= ", "; - } $btransform_ctype = Mail\Script::$btransform_ctype_array[$rule['ctype']]; $ctype_subtype = ""; if ($rule['field_ctype_val']) @@ -1079,7 +1069,6 @@ class mail_sieve $ctype_subtype = "/"; } $complete .= " body :content " . " \"" . $btransform_ctype . $ctype_subtype . $rule['field_ctype_val'] . "\"" . " :contains \"\""; - $started = 1; //error_log(__CLASS__."::".__METHOD__.array2string(Mail\Script::$btransform_ctype_array)); } if (!$rule['unconditional']) diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index c409f362b5..969103124b 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -2803,7 +2803,8 @@ $filter['before']= date("d-M-Y", $cutoffdate2); } //error_log(__METHOD__.__LINE__.'->'.array2string($attachment)); $filename = ($attachment['name']?$attachment['name']:($attachment['filename']?$attachment['filename']:$mailbox.'_uid'.$uid.'_part'.$part)); - Api\Header\Content::safe($attachment['attachment'], $filename, $attachment['type'], $size=0, True, $_GET['mode'] == "save"); + $size = 0; + Api\Header\Content::safe($attachment['attachment'], $filename, $attachment['type'], $size, True, $_GET['mode'] == "save"); echo $attachment['attachment']; exit(); @@ -2845,18 +2846,20 @@ $filter['before']= date("d-M-Y", $cutoffdate2); } $GLOBALS['egw']->session->commit_session(); + $headers = Horde_Mime_Headers::parseHeaders($message); + $subject = str_replace('$$','__',Mail::decode_header($headers['SUBJECT'])); if (!$display) { - $headers = Horde_Mime_Headers::parseHeaders($message); - $subject = str_replace('$$','__',Mail::decode_header($headers['SUBJECT'])); $subject = Api\Mail::clean_subject_for_filename($subject); - Api\Header\Content::safe($message, $subject.".eml", $mime='message/rfc822', $size=0, true, true); + $mime='message/rfc822'; + Api\Header\Content::safe($message, $subject.".eml", $mime); echo $message; } else { $subject = Api\Mail::clean_subject_for_filename($subject); - Api\Header\Content::safe($message, $subject.".eml", $mime='text/html', $size=0, true, false); + $mime='text/html'; $size=0; + Api\Header\Content::safe($message, $subject.".eml", $mime, $size, true, false); print '
'. htmlspecialchars($message, ENT_NOQUOTES|ENT_SUBSTITUTE, 'utf-8') .'
'; } } @@ -3387,7 +3390,11 @@ $filter['before']= date("d-M-Y", $cutoffdate2); $body = ''; //error_log(__METHOD__.array2string($bodyParts)); //exit; - if (empty($bodyParts)) return ""; + if (empty($bodyParts)) + { + $ret = ''; + return $ret; + } foreach((array)$bodyParts as $singleBodyPart) { if (!isset($singleBodyPart['body'])) { $singleBodyPart['body'] = $this->getdisplayableBody($singleBodyPart,$modifyURI,$useTidy); @@ -3462,26 +3469,15 @@ $filter['before']= date("d-M-Y", $cutoffdate2); // create links for websites if ($modifyURI) $newBody = Api\Html::activate_links($newBody); - //error_log(__METHOD__.__LINE__.'..'.$newBody); - // redirect links for websites if you use no cookies - #if (!($GLOBALS['egw_info']['server']['usecookies'])) - # $newBody = preg_replace("/href=(\"|\')((http(s?):\/\/)|(www\.))([\w,\-,\/,\?,\=,\.,&,!\n,\%,@,\(,\),\*,#,:,~,\+]+)(\"|\')/ie", - # "'href=\"$webserverURL/redirect.php?go='.@htmlentities(urlencode('http$4://$5$6'),ENT_QUOTES,\"Mail::$displayCharset\").'\"'", $newBody); // create links for email addresses - //TODO:if ($modifyURI) $this->parseEmail($newBody); // create links for inline images if ($modifyURI) { $newBody = self::resolve_inline_images($newBody, $this->mailbox, $this->uid, $this->partID, 'plain'); } - //TODO:$newBody = $this->highlightQuotes($newBody); // to display a mailpart of mimetype plain/text, may be better taged as preformatted - #$newBody = nl2br($newBody); - // since we do not display the message as HTML anymore we may want to insert good linebreaking (for visibility). - //error_log(__METHOD__.__LINE__.'..'.$newBody); - // dont break lines that start with > (> as the text was processed with htmlentities before) $newBody = "
".Mail::wordwrap($newBody,90,"\n",'>')."
"; } else @@ -3503,22 +3499,17 @@ $filter['before']= date("d-M-Y", $cutoffdate2); { $newBody = $cleaned; } - if (!$preserveHTML) // ToDo KL: $preserveHTML is NOT initialised, so always if is dead code + // filter only the 'body', as we only want that part, if we throw away the Api\Html + if (preg_match('`(]*>)(.+?)(.*?)`ims', $newBody, $matches) && !empty($matches[2])) { - // filter only the 'body', as we only want that part, if we throw away the Api\Html - preg_match('`(]*>)(.+?)(.*?)`ims', $newBody, $matches=array()); - if ($matches[2]) - { - $hasOther = true; - $newBody = $matches[2]; - } + $hasOther = true; + $newBody = $matches[2]; } } else { // htmLawed filter only the 'body' - preg_match('`(]*>)(.+?)(.*?)`ims', $newBody, $matches=array()); - if ($matches[2]) + if (preg_match('`(]*>)(.+?)(.*?)`ims', $newBody, $matches)&& !empty($matches[2])) { $hasOther = true; $newBody = $matches[2]; @@ -3528,28 +3519,11 @@ $filter['before']= date("d-M-Y", $cutoffdate2); // as we switched off HTMLaweds tidy functionality $newBody = str_replace(array('&','

',"
 
",'
 
'),array('&','
','
','
'),$newBody); $newBody = $htmLawed->run($newBody,Mail::$htmLawed_config); - if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3]; $alreadyHtmlLawed=true; } // do the cleanup, set for the use of purifier - //$newBodyBuff = $newBody; - /* if (!$alreadyHtmlLawed)*/ Mail::getCleanHTML($newBody); -/* - // in a way, this tests if we are having real utf-8 (the displayCharset) by now; we should if charsets reported (or detected) are correct - if (strtoupper(Mail::$displayCharset) == 'UTF-8') - { - $test = @json_encode($newBody); - //error_log(__METHOD__.__LINE__.' ->'.strlen($singleBodyPart['body']).' Error:'.json_last_error().'<- BodyPart:#'.$test.'#'); - if (($test=="null" || $test === false || is_null($test)) && strlen($newBody)>0) - { - $newBody = $newBodyBuff; - $tv = Mail::$htmLawed_config['tidy']; - Mail::$htmLawed_config['tidy'] = 0; - Mail::getCleanHTML($newBody); - Mail::$htmLawed_config['tidy'] = $tv; - } - } -*/ + Mail::getCleanHTML($newBody); + // removes stuff between http and ?http $Protocol = '(http:\/\/|(ftp:\/\/|https:\/\/))'; // only http:// gets removed, other protocolls are shown $newBody = preg_replace('~'.$Protocol.'[^>]*\?'.$Protocol.'~sim','$1',$newBody); // removes stuff between http:// and ?http:// @@ -3558,10 +3532,6 @@ $filter['before']= date("d-M-Y", $cutoffdate2); "\\1@\\2.\\3", $newBody); - // redirect links for websites if you use no cookies - #if (!($GLOBALS['egw_info']['server']['usecookies'])) { //do it all the time, since it does mask the mailadresses in urls - //TODO:if ($modifyURI) $this->parseHREF($newBody); - #} // create links for inline images if ($modifyURI) { @@ -3872,6 +3842,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2); //error_log(__METHOD__.__LINE__.array2string($_formData)); if (empty($_formData['file'])) $_formData['file'] = $_formData['tmp_name']; // check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.) + $alert_msg = ''; try { $tmpFileName = Mail::checkFileBasics($_formData,$importID); @@ -4909,7 +4880,8 @@ $filter['before']= date("d-M-Y", $cutoffdate2); $this->mail_bo->deleteMessages('all',$junkFolder,'remove_immediately'); $heirarchyDelimeter = $this->mail_bo->getHierarchyDelimiter(true); - $fShortName = array_pop(explode($heirarchyDelimeter, $junkFolder)); + $parts = explode($heirarchyDelimeter, $junkFolder); + $fShortName = array_pop($parts); $fStatus = array( $icServerID.self::$delimiter.$junkFolder => lang($fShortName) ); @@ -4959,7 +4931,8 @@ $filter['before']= date("d-M-Y", $cutoffdate2); $this->mail_bo->compressFolder($trashFolder); $heirarchyDelimeter = $this->mail_bo->getHierarchyDelimiter(true); - $fShortName = array_pop(explode($heirarchyDelimeter, $trashFolder)); + $parts = explode($heirarchyDelimeter, $trashFolder); + $fShortName = array_pop($parts); $fStatus = array( $icServerID.self::$delimiter.$trashFolder => lang($fShortName) ); @@ -5077,8 +5050,8 @@ $filter['before']= date("d-M-Y", $cutoffdate2); if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate //error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate); $filter = array( - 'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')), - 'type' => ($query['cat_id']?$query['cat_id']:(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?'quick':'subject')), + 'filterName' => lang('subject'), + 'type' => ($query['cat_id']?$query['cat_id']:'subject'), 'string' => $query['search'], 'status' => 'any',//this is a status change. status will be manipulated later on //'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2) @@ -5112,12 +5085,14 @@ $filter['before']= date("d-M-Y", $cutoffdate2); { $filter2toggle['status'][] = $query['filter']; } + $reverse = 1; + $rByUid = true; $_sRt = $this->mail_bo->getSortedList( $folder, $sort = 0, - $reverse = 1, + $reverse, $filter2toggle, - $rByUid = true, + $rByUid, false ); $messageListForToggle = $_sRt['match']->ids; @@ -5126,12 +5101,14 @@ $filter['before']= date("d-M-Y", $cutoffdate2); { $filter['status'][] = $query['filter']; } + $reverse = 1; + $rByUid = true; $_sR = $this->mail_bo->getSortedList( $folder, $sort = 0, - $reverse = 1, + $reverse, $filter, - $rByUid = true, + $rByUid, false ); $messageList = $_sR['match']->ids; @@ -5267,8 +5244,8 @@ $filter['before']= date("d-M-Y", $cutoffdate2); if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate //error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate); $filter = array( - 'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')), - 'type' => ($query['cat_id']?$query['cat_id']:(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?'quick':'subject')), + 'filterName' => lang('subject'), + 'type' => ($query['cat_id']?$query['cat_id']:'subject'), 'string' => $query['search'], 'status' => (!empty($query['filter'])?$query['filter']:'any'), //'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2) @@ -5429,8 +5406,8 @@ $filter['before']= date("d-M-Y", $cutoffdate2); if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate //error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate); $filter = array( - 'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')), - 'type' => ($query['cat_id']?$query['cat_id']:(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?'quick':'subject')), + 'filterName' => lang('subject'), + 'type' => ($query['cat_id']?$query['cat_id']:'subject'), 'string' => $query['search'], 'status' => (!empty($query['filter'])?$query['filter']:'any'), //'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2) @@ -5458,7 +5435,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2); $sort=0, $reverse, $filter, - $rByUid=true, + $rByUid, false ); $messageList = $_sR['match']->ids; diff --git a/mail/inc/class.mail_zpush.inc.php b/mail/inc/class.mail_zpush.inc.php index 60ef1a1111..75b8e14842 100644 --- a/mail/inc/class.mail_zpush.inc.php +++ b/mail/inc/class.mail_zpush.inc.php @@ -658,12 +658,12 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail, $this->mail->reopen($folder); // receive entire mail (header + body) // get message headers for specified message - $headers = $this->mail->getMessageEnvelope($uid, $_partID, true, $folder); + $headers = $this->mail->getMessageEnvelope($uid, '', true, $folder); // build a new mime message, forward entire old mail as file if ($preferencesArray['message_forwarding'] == 'asmail') { - $rawHeader = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID,$folder); - $rawBody = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID,$folder); + $rawHeader = $this->mail->getMessageRawHeader($smartdata->source->itemid, '',$folder); + $rawBody = $this->mail->getMessageRawBody($smartdata->source->itemid, '',$folder); $mailObject->AddStringAttachment($rawHeader.$rawBody, $headers['SUBJECT'].'.eml', 'message/rfc822'); $AltBody = $AltBody."
".lang("See Attachments for Content of the Orignial Mail").$sigTextHtml; $Body = $Body."\r\n".lang("See Attachments for Content of the Orignial Mail").$sigTextPlain; @@ -714,7 +714,7 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail, if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment)); $attachmentNames .= $attachment['name']."\n"; $attachmentData = $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder); - /*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']); + $x = $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']); ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' added part with number:'.$x); } }