diff --git a/felamimail/inc/class.bocompose.inc.php b/felamimail/inc/class.bocompose.inc.php index 5292357e2e..3ccc67d12b 100644 --- a/felamimail/inc/class.bocompose.inc.php +++ b/felamimail/inc/class.bocompose.inc.php @@ -344,6 +344,7 @@ #$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body']); $bodyParts[$i]['body'] = "
".$bodyParts[$i]['body']."
"; } + if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = bofelamimail::detect_encoding($bodyParts[$i]['body']); $bodyParts[$i]['body'] = $GLOBALS['egw']->translation->convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']); #error_log( "GetDraftData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1')); $this->sessionData['body'] .= "
". $bodyParts[$i]['body'] ; @@ -356,6 +357,7 @@ if($i>0) { $this->sessionData['body'] .= "
"; } + if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = bofelamimail::detect_encoding($bodyParts[$i]['body']); $bodyParts[$i]['body'] = $GLOBALS['egw']->translation->convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']); #error_log( "GetDraftData (Plain) CharSet".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1')); $this->sessionData['body'] .= "\r\n". $bodyParts[$i]['body'] ; @@ -610,6 +612,7 @@ #$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body'])."
"; $bodyParts[$i]['body'] = "
".$bodyParts[$i]['body']."
"; } + if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = bofelamimail::detect_encoding($bodyParts[$i]['body']); $this->sessionData['body'] .= "
".self::_getCleanHTML($GLOBALS['egw']->translation->convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet'])); #error_log( "GetReplyData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1')); @@ -632,6 +635,7 @@ } // add line breaks to $bodyParts + if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = bofelamimail::detect_encoding($bodyParts[$i]['body']); $newBody = $GLOBALS['egw']->translation->convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']); #error_log( "GetReplyData (Plain) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1')); @@ -950,6 +954,7 @@ $this->sessionData['disposition'] = $_formData['disposition']; $this->sessionData['mimeType'] = $_formData['mimeType']; $this->sessionData['to_infolog'] = $_formData['to_infolog']; + $this->sessionData['to_tracker'] = $_formData['to_tracker']; // if the body is empty, maybe someone pasted something with scripts, into the message body // this should not happen anymore, unless you call send directly, since the check was introduced with the action command if(empty($this->sessionData['body'])) @@ -977,7 +982,7 @@ // create the messages $this->createMessage($mail, $_formData, $identity, $signature); // remember the identity - if ($_formData['to_infolog'] == 'on') $fromAddress = $mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':''); + if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') $fromAddress = $mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':''); #print "
". $mail->getMessageHeader() ."


"; #print "
". $mail->getMessageBody() ."


"; #exit; @@ -1108,7 +1113,7 @@ if (is_array($this->sessionData['cc'])) $mailaddresses['cc'] = $this->sessionData['cc']; if (is_array($this->sessionData['bcc'])) $mailaddresses['bcc'] = $this->sessionData['bcc']; if (!empty($mailaddresses)) $mailaddresses['from'] = $fromAddress; - // attention: we dont return from infolog. cleanups will be done there. + // attention: we dont return from infolog/trackere. You cannot check both. cleanups will be done there. if ($_formData['to_infolog'] == 'on') { $uiinfolog =& CreateObject('infolog.infolog_ui'); $uiinfolog->import_mail( @@ -1118,6 +1123,16 @@ $this->sessionData['attachments'] ); } + if ($_formData['to_tracker'] == 'on') { + $uitracker =& CreateObject('tracker.tracker_ui'); + $uitracker->import_mail( + $mailaddresses, + $this->sessionData['subject'], + $this->convertHTMLToText($this->sessionData['body']), + $this->sessionData['attachments'] + ); + } + if(is_array($this->sessionData['attachments'])) { reset($this->sessionData['attachments']); diff --git a/felamimail/inc/class.bofelamimail.inc.php b/felamimail/inc/class.bofelamimail.inc.php index 59b64cedac..85c60b10a8 100644 --- a/felamimail/inc/class.bofelamimail.inc.php +++ b/felamimail/inc/class.bofelamimail.inc.php @@ -830,6 +830,8 @@ //$_html = str_replace("\r\n",' ',$_html); //$_html = str_replace("\t",' ',$_html); //error_log($_html); + //repair doubleencoded ampersands + $_html = str_replace('&amp;','&',$_html); self::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags self::replaceTagsCompletley($_html,'head'); // Strip out stuff in head self::replaceTagsCompletley($_html,'!\[if','',false); // Strip out stuff in ifs @@ -1664,17 +1666,27 @@ } } + /** + * getMimePartCharset - fetches the charset mimepart if it exists + * @params $_mimePartObject structure object + * @returns mixed mimepart or false if no CHARSET is found, the missing charset has to be handled somewhere else, + * as we cannot safely assume any charset as we did earlier + */ function getMimePartCharset($_mimePartObject) { - $charSet = 'iso-8859-1'; - + //$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1 + $CharsetFound=false; + //echo "#".$_mimePartObject->encoding.'#
'; if(is_array($_mimePartObject->parameters)) { if(isset($_mimePartObject->parameters['CHARSET'])) { $charSet = $_mimePartObject->parameters['CHARSET']; + $CharsetFound=true; } } - - return $charSet; + // this one is dirty, but until I find something that does the trick of detecting the encoding, .... + //if ($CharsetFound == false && $_mimePartObject->encoding == "QUOTED-PRINTABLE") $charSet = 'iso-8859-1'; //assume quoted-printable to be ISO + //if ($CharsetFound == false && $_mimePartObject->encoding == "BASE64") $charSet = 'utf-8'; // assume BASE64 to be UTF8 + return ($CharsetFound ? $charSet : $CharsetFound); } function getMultipartAlternative($_uid, $_structure, $_htmlMode) @@ -3112,6 +3124,24 @@ } return preg_match("$needle",$string); } + + /** + * detect_encoding - try to detect the encoding + * only to be used if the string in question has no structure that determines his encoding + * @param string - to be evaluated + * @returns mixed string/boolean (encoding or false + */ + static function detect_encoding($string) { + static $list = array('utf-8', 'iso-8859-1', 'windows-1251'); // list may be extended + + foreach ($list as $item) { + $sample = iconv($item, $item, $string); + if (md5($sample) == md5($string)) + return $item; + } + return false; // we may choose to return iso-8859-1 as default at some point + } + static function detect_qp(&$sting) { $needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/'; return preg_match("$needle",$string); @@ -3141,4 +3171,176 @@ } return $date2return; } + + /** + * functions to allow access to mails through other apps to fetch content + * used in infolog, tracker + */ + + /** + * get_mailcontent - fetches the actual mailcontent, and returns it as well defined array + * @param bofelamimail the bofelamimailobject to be used + * @param uid the uid of the email to be processed + * @param partid the partid of the email + * @param mailbox the mailbox, that holds the message + * @returns array with 'mailaddress'=>$mailaddress, + * 'subject'=>$subject, + * 'message'=>$message, + * 'attachments'=>$attachments, + * 'headers'=>$headers, + */ + static function get_mailcontent(&$bofelamimail,$uid,$partid='',$mailbox='') + { + //echo __METHOD__." called for $uid,$partid
"; + $headers = $bofelamimail->getMessageHeader($uid,$partid,true); + // dont force retrieval of the textpart, let felamimail preferences decide + $bodyParts = $bofelamimail->getMessageBody($uid,'',$partid); + $attachments = $bofelamimail->getMessageAttachments($uid,$partid); + + if ($bofelamimail->isSentFolder($mailbox)) $mailaddress = $headers['TO']; + elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM']; + elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER']; + if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC']; + //_debug_array($headers); + $subject = $headers['SUBJECT']; + + $message = self::getdisplayableBody($bofelamimail, $bodyParts); + $headdata = self::createHeaderInfoSection($headers); + $message = $headdata.$message; + //echo __METHOD__.'
'; + //_debug_array($attachments); + if (is_array($attachments)) + { + foreach ($attachments as $num => $attachment) + { + if ($attachment['mimeType'] == 'MESSAGE/RFC822') + { + //_debug_array($bofelamimail->getMessageHeader($uid, $attachment['partID'])); + //_debug_array($bofelamimail->getMessageBody($uid,'', $attachment['partID'])); + //_debug_array($bofelamimail->getMessageAttachments($uid, $attachment['partID'])); + $mailcontent = self::get_mailcontent($bofelamimail,$uid,$attachment['partID']); + $headdata =''; + if ($mailcontent['headers']) + { + $headdata = self::createHeaderInfoSection($mailcontent['headers']); + } + if ($mailcontent['message']) + { + $tempname =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_"); + $attachedMessages[] = array( + 'type' => 'TEXT/PLAIN', + 'name' => $mailcontent['subject'].'.txt', + 'tmp_name' => $tempname, + ); + $tmpfile = fopen($tempname,'w'); + fwrite($tmpfile,$headdata.$mailcontent['message']); + fclose($tmpfile); + } + foreach($mailcontent['attachments'] as $tmpattach => $tmpval) + { + $attachedMessages[] = $tmpval; + } + unset($attachments[$num]); + } + else + { + $attachments[$num] = array_merge($attachments[$num],$bofelamimail->getAttachment($uid, $attachment['partID'])); + if (isset($attachments[$num]['charset'])) { + if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = self::detect_encoding($attachments[$num]['attachment']); + $GLOBALS['egw']->translation->convert($attachments[$num]['attachment'],$attachments[$num]['charset']); + } + $attachments[$num]['type'] = $attachments[$num]['mimeType']; + $attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_"); + $tmpfile = fopen($attachments[$num]['tmp_name'],'w'); + fwrite($tmpfile,$attachments[$num]['attachment']); + fclose($tmpfile); + unset($attachments[$num]['attachment']); + } + } + if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages); + } + return array( + 'mailaddress'=>$mailaddress, + 'subject'=>$subject, + 'message'=>$message, + 'attachments'=>$attachments, + 'headers'=>$headers, + ); + } + + /** + * createHeaderInfoSection - creates a textual headersection from headerobject + * @params header headerarray may contain SUBJECT,FROM,SENDER,TO,CC,BCC,DATE,PRIORITY,IMPORTANCE + * @returns string a preformatted string with the information of the header worked into it + */ + static function createHeaderInfoSection($header,$headline='') + { + $headdata = null; + if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT']."\n"; + if ($header['FROM']) $headdata .= lang('from').': '.$header['FROM']."\n"; + if ($header['SENDER']) $headdata .= lang('sender').': '.$header['SENDER']."\n"; + if ($header['TO']) $headdata .= lang('to').': '.$header['TO']."\n"; + if ($header['CC']) $headdata .= lang('cc').': '.$header['CC']."\n"; + if ($header['BCC']) $headdata .= lang('bcc').': '.$header['BCC']."\n"; + if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE']."\n"; + if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY']."\n"; + if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE']."\n"; + //if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\ + if (!empty($headdata)) + { + if (!empty($headline)) $headdata = "---------------------------- $headline ----------------------------\n".$headdata; + if (empty($headline)) $headdata = "--------------------------------------------------------\n".$headdata; + $headdata .= "--------------------------------------------------------\n"; + } + else + { + $headdata = "--------------------------------------------------------\n"; + } + return $headdata; + } + + /** + * getdisplayableBody - creates the bodypart of the email as textual representation + * @param bofelamimail the bofelamimailobject to be used + * @params bodyPorts array with the bodyparts + * @returns string a preformatted string with the mails converted to text + */ + static function &getdisplayableBody(&$bofelamimail, $bodyParts) + { + for($i=0; $itranslation->convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']); + + if ($bodyParts[$i]['mimeType'] == 'text/html') { + // convert HTML to text, as we dont want HTML in infologs + $newBody = html::purify($newBody); + $newBody = $bofelamimail->convertHTMLToText($newBody,true); + $bofelamimail->getCleanHTML($newBody); // new Body passed by reference + $message .= $newBody; + continue; + } + $newBody = strip_tags($newBody); + $newBody = explode("\n",$newBody); + // create it new, with good line breaks + reset($newBody); + while(list($key,$value) = @each($newBody)) + { + if (trim($value) != '') { + #if ($value != "\r") $value .= "\n"; + } else { + // if you want to strip all empty lines uncomment the following + #continue; + } + $message .= $bofelamimail->wordwrap($value,75,"\n"); + } + } + return $message; + } } diff --git a/felamimail/inc/class.uicompose.inc.php b/felamimail/inc/class.uicompose.inc.php index edcd65e991..aabb41269b 100644 --- a/felamimail/inc/class.uicompose.inc.php +++ b/felamimail/inc/class.uicompose.inc.php @@ -107,6 +107,7 @@ $formData['mimeType'] = $this->bocompose->stripSlashes($_POST['mimeType']); $formData['disposition'] = (bool)$_POST['disposition']; $formData['to_infolog'] = $_POST['to_infolog']; + $formData['to_tracker'] = $_POST['to_tracker']; //$formData['mailbox'] = $_GET['mailbox']; if((bool)$_POST['printit'] == true) { $formData['printit'] = 1; @@ -404,8 +405,18 @@ $this->t->set_var('lang_save_as_infolog',''); $this->t->set_var('infolog_checkbox',''); } + if ($GLOBALS['egw_info']['user']['apps']['tracker']) + { + $this->t->set_var('trackerImage',html::image('felamimail','to_tracker',lang('Save as tracker'),'width="17px" height="17px" valign="middle"' )); + $this->t->set_var('lang_save_as_infolog',($GLOBALS['egw_info']['user']['apps']['infolog']?lang('Save:'):lang('Save as tracker'))); + $this->t->set_var('tracker_checkbox',''); + } else { + $this->t->set_var('trackerImage',''); + $this->t->set_var('tracker_checkbox',''); + } $this->t->set_var('lang_no_recipient',lang('No recipient address given!')); $this->t->set_var('lang_no_subject',lang('No subject given!')); + $this->t->set_var('lang_infolog_tracker_not_both',lang("You can either choose to save as infolog OR tracker, not both.")); $this->t->pparse("out","header"); // prepare signatures, the selected sig may be used on top of the body diff --git a/felamimail/inc/class.uidisplay.inc.php b/felamimail/inc/class.uidisplay.inc.php index ce5b9b42f8..ec702ab7fa 100644 --- a/felamimail/inc/class.uidisplay.inc.php +++ b/felamimail/inc/class.uidisplay.inc.php @@ -974,12 +974,11 @@ $senderAddress .= 'undisclosed-recipients'; continue; } - if($addressData['PERSONAL_NAME'] != 'NIL') { $newSenderAddress = $addressData['RFC822_EMAIL'] != 'NIL' ? $addressData['RFC822_EMAIL'] : $addressData['EMAIL']; if ($decode) $newSenderAddress = bofelamimail::decode_header($newSenderAddress); $decodedPersonalName = ($decode ? bofelamimail::decode_header($addressData['PERSONAL_NAME']):$addressData['PERSONAL_NAME']); - + if ($decode) $addressData['EMAIL'] = bofelamimail::decode_header($addressData['EMAIL']); $realName = $decodedPersonalName; // add mailaddress if ($allwaysShowMailAddress) { @@ -1030,6 +1029,7 @@ lang('add to addressbook')); } } else { + if ($decode) $addressData['EMAIL'] = bofelamimail::decode_header($addressData['EMAIL']); $linkData = array ( 'menuaction' => 'felamimail.uicompose.compose', 'send_to' => base64_encode($addressData['EMAIL']) @@ -1063,7 +1063,6 @@ } } } - return $senderAddress; } @@ -1229,6 +1228,7 @@ { $singleBodyPart['body'] = preg_replace($sar,$rar,$singleBodyPart['body']); } + if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = bofelamimail::detect_encoding($singleBodyPart['body']); $singleBodyPart['body'] = $GLOBALS['egw']->translation->convert( $singleBodyPart['body'], strtolower($singleBodyPart['charSet']) diff --git a/felamimail/inc/class.uiwidgets.inc.php b/felamimail/inc/class.uiwidgets.inc.php index f3764af7b7..9eae1e854d 100644 --- a/felamimail/inc/class.uiwidgets.inc.php +++ b/felamimail/inc/class.uiwidgets.inc.php @@ -672,7 +672,7 @@ $image - + ".$this->navbarSeparator().$this->displayMessageActions($headerData, $_folderName, $_icServer,true)." @@ -805,6 +805,16 @@ } $to_infologURL = $GLOBALS['egw']->link('/index.php',$linkData); + $linkData = array( + 'menuaction' => 'tracker.tracker_ui.import_mail', + 'uid' => $_headerData['uid'], + 'mailbox' => base64_encode($_folderName) + ); + if($_headerData['partid'] != '') { + $linkData['part'] = $_headerData['partid']; + } + $to_trackerURL = $GLOBALS['egw']->link('/index.php',$linkData); + // viewheader url $linkData = array ( 'menuaction' => 'felamimail.uidisplay.displayHeader', @@ -845,7 +855,13 @@ 'action' => "window.open('$to_infologURL','_blank','dependent=yes,width=".$i_width.",height=".$i_height.",scrollbars=yes,status=yes')", 'tooltip' => lang('save as infolog')); } - + if ($GLOBALS['egw_info']['user']['apps']['tracker']) + { + list($i_width,$i_height) = explode('x',egw_link::get_registry('tracker','add_popup')); + $navbarImages['to_tracker'] = array( + 'action' => "egw_openWindowCentered('$to_trackerURL','_blank',".$i_width.",".$i_height.")", + 'tooltip' => lang('save as tracker')); + } // save email as $navbarImages['fileexport'] = array( 'action' => ($_forceNewWindow ? "window.open('$saveMessageURL','_blank','dependent=yes,width=100,height=100,scrollbars=yes,status=yes')": "window.location.href = '$saveMessageURL'"), diff --git a/felamimail/templates/default/composeForm.tpl b/felamimail/templates/default/composeForm.tpl index e8b069eef5..131243d40a 100644 --- a/felamimail/templates/default/composeForm.tpl +++ b/felamimail/templates/default/composeForm.tpl @@ -38,6 +38,14 @@ alert("{lang_no_subject}"); return false; } + // check to infolog/ to tracker. Only one can be checked. + var toinfolog = document.getElementById('to_infolog'); + var totracker = document.getElementById('to_tracker'); + if (toinfolog.checked==true && totracker.checked==true) + { + alert("{lang_infolog_tracker_not_both}"); + return false; + } return true; } @@ -81,6 +89,12 @@ {infolog_checkbox} + + + + + {tracker_checkbox} + diff --git a/felamimail/templates/default/images/to_tracker.png b/felamimail/templates/default/images/to_tracker.png new file mode 100644 index 0000000000..6eb0151445 Binary files /dev/null and b/felamimail/templates/default/images/to_tracker.png differ diff --git a/infolog/inc/class.infolog_ui.inc.php b/infolog/inc/class.infolog_ui.inc.php index e029efe402..101ed09b4f 100644 --- a/infolog/inc/class.infolog_ui.inc.php +++ b/infolog/inc/class.infolog_ui.inc.php @@ -1523,7 +1523,7 @@ class infolog_ui { $bofelamimail->reopen($attachment['folder']); - $mailcontent = self::get_mailcontent($bofelamimail,$attachment['uid'],$attachment['partID'],$attachment['folder']); + $mailcontent = bofelamimail::get_mailcontent($bofelamimail,$attachment['uid'],$attachment['partID'],$attachment['folder']); //_debug_array($mailcontent['attachments']); foreach($mailcontent['attachments'] as $tmpattach => $tmpval) { @@ -1557,7 +1557,7 @@ class infolog_ui $toaddr = array(); foreach(array('to','cc','bcc') as $x) if (is_array($_to_emailAddress[$x]) && !empty($_to_emailAddress[$x])) $toaddr = array_merge($toaddr,$_to_emailAddress[$x]); //_debug_array($attachments); - $body = self::createHeaderInfoSection(array('FROM'=>$_to_emailAddress['from'], + $body = bofelamimail::createHeaderInfoSection(array('FROM'=>$_to_emailAddress['from'], 'TO'=>(!empty($_to_emailAddress['to'])?implode(',',$_to_emailAddress['to']):null), 'CC'=>(!empty($_to_emailAddress['cc'])?implode(',',$_to_emailAddress['cc']):null), 'BCC'=>(!empty($_to_emailAddress['bcc'])?implode(',',$_to_emailAddress['bcc']):null), @@ -1575,7 +1575,7 @@ class infolog_ui $bofelamimail->openConnection(); $bofelamimail->reopen($mailbox); - $mailcontent = self::get_mailcontent($bofelamimail,$uid,$partid,$mailbox); + $mailcontent = bofelamimail::get_mailcontent($bofelamimail,$uid,$partid,$mailbox); return $this->edit($this->bo->import_mail( $mailcontent['mailaddress'], @@ -1591,150 +1591,6 @@ class infolog_ui exit; } - /** - * fetches the actual mailcontent - */ - static function get_mailcontent(&$bofelamimail,$uid,$partid='',$mailbox='') - { - //echo __METHOD__." called for $uid,$partid
"; - $headers = $bofelamimail->getMessageHeader($uid,$partid,true); - // dont force retrieval of the textpart, let felamimail preferences decide - $bodyParts = $bofelamimail->getMessageBody($uid,'',$partid); - $attachments = $bofelamimail->getMessageAttachments($uid,$partid); - - if ($bofelamimail->isSentFolder($mailbox)) $mailaddress = $headers['TO']; - elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM']; - elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER']; - if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC']; - //_debug_array($headers); - $subject = $headers['SUBJECT']; - - $message = self::getdisplayableBody($bofelamimail, $bodyParts); - $headdata = self::createHeaderInfoSection($headers); - $message = $headdata.$message; - //echo __METHOD__.'
'; - //_debug_array($attachments); - if (is_array($attachments)) - { - foreach ($attachments as $num => $attachment) - { - if ($attachment['mimeType'] == 'MESSAGE/RFC822') - { - //_debug_array($bofelamimail->getMessageHeader($uid, $attachment['partID'])); - //_debug_array($bofelamimail->getMessageBody($uid,'', $attachment['partID'])); - //_debug_array($bofelamimail->getMessageAttachments($uid, $attachment['partID'])); - $mailcontent = self::get_mailcontent($bofelamimail,$uid,$attachment['partID']); - $headdata =''; - if ($mailcontent['headers']) - { - $headdata = self::createHeaderInfoSection($mailcontent['headers']); - } - if ($mailcontent['message']) - { - $tempname =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_"); - $attachedMessages[] = array( - 'type' => 'TEXT/PLAIN', - 'name' => $mailcontent['subject'].'.txt', - 'tmp_name' => $tempname, - ); - $tmpfile = fopen($tempname,'w'); - fwrite($tmpfile,$headdata.$mailcontent['message']); - fclose($tmpfile); - } - foreach($mailcontent['attachments'] as $tmpattach => $tmpval) - { - $attachedMessages[] = $tmpval; - } - unset($attachments[$num]); - } - else - { - $attachments[$num] = array_merge($attachments[$num],$bofelamimail->getAttachment($uid, $attachment['partID'])); - if (isset($attachments[$num]['charset'])) { - $GLOBALS['egw']->translation->convert($attachments[$num]['attachment'],$attachments[$num]['charset']); - } - $attachments[$num]['type'] = $attachments[$num]['mimeType']; - $attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_"); - $tmpfile = fopen($attachments[$num]['tmp_name'],'w'); - fwrite($tmpfile,$attachments[$num]['attachment']); - fclose($tmpfile); - unset($attachments[$num]['attachment']); - } - } - if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages); - } - return array( - 'mailaddress'=>$mailaddress, - 'subject'=>$subject, - 'message'=>$message, - 'attachments'=>$attachments, - 'headers'=>$headers, - ); - } - - static function createHeaderInfoSection($header) - { - $headdata = null; - if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT']."\n"; - if ($header['FROM']) $headdata .= lang('from').': '.$header['FROM']."\n"; - if ($header['SENDER']) $headdata .= lang('sender').': '.$header['SENDER']."\n"; - if ($header['TO']) $headdata .= lang('to').': '.$header['TO']."\n"; - if ($header['CC']) $headdata .= lang('cc').': '.$header['CC']."\n"; - if ($header['BCC']) $headdata .= lang('bcc').': '.$header['BCC']."\n"; - if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE']."\n"; - if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY']."\n"; - if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE']."\n"; - //if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\ - if (!empty($headdata)) - { - $headdata = "--------------------------------------------------------\n".$headdata; - $headdata .= "--------------------------------------------------------\n"; - } - else - { - $headdata = "--------------------------------------------------------\n"; - } - return $headdata; - } - - static function &getdisplayableBody(&$bofelamimail, $bodyParts) - { - for($i=0; $itranslation->convert($bodyParts[$i]['body'], $bodyParts[$i]['charSet']); - - if ($bodyParts[$i]['mimeType'] == 'text/html') { - // convert HTML to text, as we dont want HTML in infologs - $newBody = html::purify($newBody); - $newBody = $bofelamimail->convertHTMLToText($newBody,true); - $bofelamimail->getCleanHTML($newBody); // new Body passed by reference - $message .= $newBody; - continue; - } - $newBody = strip_tags($newBody); - $newBody = explode("\n",$newBody); - // create it new, with good line breaks - reset($newBody); - while(list($key,$value) = @each($newBody)) - { - if (trim($value) != '') { - #if ($value != "\r") $value .= "\n"; - } else { - // if you want to strip all empty lines uncomment the following - #continue; - } - $message .= $bofelamimail->wordwrap($value,75,"\n"); - } - } - return $message; - } /** * return javascript to open compose window to print the Infolog