From 9c2ff7cf803d5e5aa0608712b5809f02b187428d Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Mon, 17 Jun 2013 14:25:20 +0000 Subject: [PATCH] provide a more presentable attachment section --- mail/inc/class.mail_bopreferences.inc.php | 12 +- mail/inc/class.mail_ui.inc.php | 344 +++++++++++----------- mail/js/app.js | 7 +- mail/templates/default/app.css | 2 + 4 files changed, 195 insertions(+), 170 deletions(-) diff --git a/mail/inc/class.mail_bopreferences.inc.php b/mail/inc/class.mail_bopreferences.inc.php index f350ce4e90..c6dd856681 100644 --- a/mail/inc/class.mail_bopreferences.inc.php +++ b/mail/inc/class.mail_bopreferences.inc.php @@ -361,7 +361,17 @@ class mail_bopreferences extends mail_sopreferences } } // make sure there is one profile marked as default (either 0 or the one found) - $profileData->identities[$IdIsDefault]->default = true; + $markedAsDefault = false; + foreach ($profileData->identities as &$id) + { + if ($id->id == $idIsDefault) + { + $id->default = true; + $markedAsDefault = true; + } + } + // none found; mark identity 0 as default + if ($markedAsDefault == false) $profileData->identities[0]->default = true; $userPrefs = $this->mergeUserAndProfilePrefs($userPreferences,$profileData,$profileID); $profileData->setPreferences($userPrefs); diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index 0d38e51798..ffc875c448 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -1511,166 +1511,8 @@ unset($query['actions']); $fetchEmbeddedImages = false; if ($htmlOptions !='always_display') $fetchEmbeddedImages = true; $attachments = $this->mail_bo->getMessageAttachments($uid, $partID, '',$fetchEmbeddedImages); -//_debug_array($headers); - // attachments -/* if(is_array($attachments) && count($attachments) > 0 && count($attachments) > 4) { - // this is to account for maxheight minheight of the attachment div - $this->t->set_var('attachment_div_height',' bottom:'.(count($attachments)>4?(count($attachments)*20<=240?count($attachments)*20:240):80).'px'); - } else { - $this->t->set_var('attachment_div_height',''); // app.css bodyDIVAttachment - } -*/ - if (is_array($attachments) && count($attachments) > 0) { - $url_img_vfs = html::image('filemanager','navbar', lang('Filemanager'), ' height="16"'); - $url_img_vfs_save_all = html::image('felamimail','save_all', lang('Save all')); - - $detectedCharSet=$charset2use=mail_bo::$displayCharset; - foreach ($attachments as $key => $value) - { -//_debug_array($value); - #$detectedCharSet = mb_detect_encoding($value['name'].'a',strtoupper($this->displayCharset).",UTF-8, ISO-8559-1"); - if (function_exists('mb_convert_variables')) mb_convert_variables("UTF-8","ISO-8559-1",$value['name']); # iso 2 UTF8 - //if (mb_convert_variables("ISO-8859-1","UTF-8",$value['name'])){echo "Juhu utf8 2 ISO\n";}; - //echo $value['name']."\n"; - $filename=htmlentities($value['name'], ENT_QUOTES, $detectedCharSet); -/* - $this->t->set_var('row_color',$this->rowColor[($key+1)%2]); - $this->t->set_var('filename',($value['name'] ? ( $filename ? $filename : $value['name'] ) : lang('(no subject)'))); - $this->t->set_var('mimetype',mime_magic::mime2label($value['mimeType'])); - $this->t->set_var('size',egw_vfs::hsize($value['size'])); - $this->t->set_var('attachment_number',$key); -*/ - switch(strtoupper($value['mimeType'])) - { - case 'MESSAGE/RFC822': - $linkData = array - ( - 'menuaction' => 'mail.mail_ui.displayMessage', - 'id' => $rowID, - 'part' => $value['partID'], - 'mailbox' => base64_encode($mailbox), - 'is_winmail' => $value['is_winmail'] - ); - $windowName = 'displayMessage_'. $rowID.'_'.$value['partID']; - $linkView = "egw_openWindowCentered('".$GLOBALS['egw']->link('/index.php',$linkData)."','$windowName',700,egw_getWindowOuterHeight());"; - break; - case 'IMAGE/JPEG': - case 'IMAGE/PNG': - case 'IMAGE/GIF': - case 'IMAGE/BMP': - case 'APPLICATION/PDF': - case 'TEXT/PLAIN': - case 'TEXT/HTML': - case 'TEXT/DIRECTORY': - $sfxMimeType = $value['mimeType']; - $buff = explode('.',$value['name']); - $suffix = ''; - if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime - if (!empty($suffix)) $sfxMimeType = mime_magic::ext2mime($suffix); - if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD') - { - $attachments[$key]['mimeType'] = $sfxMimeType; - $value['mimeType'] = strtoupper($sfxMimeType); - } - case 'TEXT/X-VCARD': - case 'TEXT/VCARD': - case 'TEXT/CALENDAR': - case 'TEXT/X-VCALENDAR': - $linkData = array - ( - 'menuaction' => 'mail.mail_ui.getAttachment', - 'id' => $rowID, - 'part' => $value['partID'], - 'is_winmail' => $value['is_winmail'], - 'mailbox' => base64_encode($mailbox), - ); - $windowName = 'displayAttachment_'. $uid; - $reg = '800x600'; - // handle calendar/vcard - if (strtoupper($value['mimeType'])=='TEXT/CALENDAR') - { - $windowName = 'displayEvent_'. $rowID; - $reg2 = egw_link::get_registry('calendar','view_popup'); - } - if (strtoupper($value['mimeType'])=='TEXT/X-VCARD' || strtoupper($value['mimeType'])=='TEXT/VCARD') - { - $windowName = 'displayContact_'. $rowID; - $reg2 = egw_link::get_registry('addressbook','add_popup'); - } - // apply to action - list($width,$height) = explode('x',(!empty($reg2) ? $reg2 : $reg)); - $linkView = "egw_openWindowCentered('".$GLOBALS['egw']->link('/index.php',$linkData)."','$windowName',$width,$height);"; - break; - default: - $linkData = array - ( - 'menuaction' => 'mail.mail_ui.getAttachment', - 'id' => $rowID, - 'part' => $value['partID'], - 'is_winmail' => $value['is_winmail'], - 'mailbox' => base64_encode($mailbox), - ); - $linkView = "window.location.href = '".$GLOBALS['egw']->link('/index.php',$linkData)."';"; - break; - } -error_log(__METHOD__.__LINE__.$linkView); - $attachmentHTML[] = ''. - ($value['name'] ? ( $filename ? $filename : $value['name'] ) : lang('(no subject)')). - ''; -// $this->t->set_var("link_view",$linkView); -// $this->t->set_var("target",$target); - - $linkData = array - ( - 'menuaction' => 'mail.mail_ui.getAttachment', - 'mode' => 'save', - 'id' => $rowID, - 'part' => $value['partID'], - 'is_winmail' => $value['is_winmail'], - 'mailbox' => base64_encode($mailbox), - ); - //$this->t->set_var("link_save",$GLOBALS['egw']->link('/index.php',$linkData)); - - if ($GLOBALS['egw_info']['user']['apps']['filemanager']) - { - $link_vfs_save = egw::link('/index.php',array( - 'menuaction' => 'filemanager.filemanager_select.select', - 'mode' => 'saveas', - 'name' => $value['name'], - 'mime' => strtolower($value['mimeType']), - 'method' => 'felamimail.uidisplay.vfsSaveAttachment', - 'id' => $mailbox.'::'.$uid.'::'.$value['partID'].'::'.$value['is_winmail'], - 'label' => lang('Save'), - )); - $vfs_save = "$url_img_vfs"; - // add save-all icon for first attachment - if (!$key && count($attachments) > 1) - { - foreach ($attachments as $key => $value) - { - //$rowID - $ids["id[$key]"] = $rowID.'::'.$value['partID'].'::'.$value['is_winmail'].'::'.$value['name']; - } - $link_vfs_save = egw::link('/index.php',array( - 'menuaction' => 'filemanager.filemanager_select.select', - 'mode' => 'select-dir', - 'method' => 'mail.mail_ui.vfsSaveAttachment', - 'label' => lang('Save all'), - )+$ids); - $vfs_save .= "\n$url_img_vfs_save_all"; - } - //$this->t->set_var('vfs_save',$vfs_save); - } - else - { - //$this->t->set_var('vfs_save',''); - } - //$this->t->parse('attachment_rows','message_attachement_row',True); - } - } else { - //$this->t->set_var('attachment_rows',''); - } - + //_debug_array($headers); + $attachmentHTMLBlock = self::createAttachmentBlock($attachments, $rowID, $uid, $mailbox); $webserverURL = $GLOBALS['egw_info']['server']['webserver_url']; $nonDisplayAbleCharacters = array('[\016]','[\017]', @@ -1679,7 +1521,7 @@ error_log(__METHOD__.__LINE__.$linkView); #print "
";print_r($rawheaders);print"
";exit; $mailBody = $this->get_load_email_data($uid, $partID, $mailbox,false); -//error_log(__METHOD__.__LINE__.$mailBody); + //error_log(__METHOD__.__LINE__.$mailBody); $this->mail_bo->closeConnection(); $etpl = new etemplate_new('mail.display'); @@ -1695,19 +1537,185 @@ error_log(__METHOD__.__LINE__.$linkView); ), )); */ -egw_framework::set_onload(""); + egw_framework::set_onload(""); $subject = mail_bo::htmlspecialchars($this->mail_bo->decode_subject(preg_replace($nonDisplayAbleCharacters,'',$envelope['SUBJECT']),false), mail_bo::$displayCharset); if (empty($subject)) $subject = lang('no subject'); -$content['msg'] = $subject.(is_array($error_msg)?implode("
",$error_msg):$error_msg); -$content['mail_displaysubject'] = $subject; -$content['mail_displaybody'] = $mailBody; -//_debug_array($attachments); -$content['mail_displayattachments'] = (count($attachments)?implode('
',$attachmentHTML):''); -$readonlys = $preserv = $content; + $content['msg'] = $subject.(is_array($error_msg)?implode("
",$error_msg):$error_msg); + $content['mail_displaysubject'] = $subject; + $content['mail_displaybody'] = $mailBody; + //_debug_array($attachments); + $content['mail_displayattachments'] = $attachmentHTMLBlock; + $readonlys = $preserv = $content; echo $etpl->exec('mail.mail_ui.displayMessage',$content,$sel_options,$readonlys,$preserv,2); } + /** + * createAttachmentBlock + * helper function to create the attachment block/table + * + * @param array $attachments, array with the attachments information + * @param string $rowID, rowid of the message + * @param int $uid, uid of the message + * @param string $mailbox, the mailbox identifier + * @return string html or empty string + */ + static function createAttachmentBlock($attachments, $rowID, $uid, $mailbox) + { + $attachmentHTMLBlock=''; + if (is_array($attachments) && count($attachments) > 0) { + $url_img_vfs = html::image('filemanager','navbar', lang('Filemanager'), ' height="16"'); + $url_img_vfs_save_all = html::image('felamimail','save_all', lang('Save all')); + + $detectedCharSet=$charset2use=mail_bo::$displayCharset; + foreach ($attachments as $key => $value) + { + //_debug_array($value); + #$detectedCharSet = mb_detect_encoding($value['name'].'a',strtoupper($this->displayCharset).",UTF-8, ISO-8559-1"); + if (function_exists('mb_convert_variables')) mb_convert_variables("UTF-8","ISO-8559-1",$value['name']); # iso 2 UTF8 + //if (mb_convert_variables("ISO-8859-1","UTF-8",$value['name'])){echo "Juhu utf8 2 ISO\n";}; + //echo $value['name']."\n"; + $filename=htmlentities($value['name'], ENT_QUOTES, $detectedCharSet); + + $attachmentHTML[$key]['filename']= ($value['name'] ? ( $filename ? $filename : $value['name'] ) : lang('(no subject)')); + $attachmentHTML[$key]['mimetype']=mime_magic::mime2label($value['mimeType']); + $attachmentHTML[$key]['size']=egw_vfs::hsize($value['size']); + $attachmentHTML[$key]['attachment_number']=$key; + + switch(strtoupper($value['mimeType'])) + { + case 'MESSAGE/RFC822': + $linkData = array + ( + 'menuaction' => 'mail.mail_ui.displayMessage', + 'id' => $rowID, + 'part' => $value['partID'], + 'mailbox' => base64_encode($mailbox), + 'is_winmail' => $value['is_winmail'] + ); + $windowName = 'displayMessage_'. $rowID.'_'.$value['partID']; + $linkView = "egw_openWindowCentered('".$GLOBALS['egw']->link('/index.php',$linkData)."','$windowName',700,egw_getWindowOuterHeight());"; + break; + case 'IMAGE/JPEG': + case 'IMAGE/PNG': + case 'IMAGE/GIF': + case 'IMAGE/BMP': + case 'APPLICATION/PDF': + case 'TEXT/PLAIN': + case 'TEXT/HTML': + case 'TEXT/DIRECTORY': + $sfxMimeType = $value['mimeType']; + $buff = explode('.',$value['name']); + $suffix = ''; + if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime + if (!empty($suffix)) $sfxMimeType = mime_magic::ext2mime($suffix); + if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD') + { + $attachments[$key]['mimeType'] = $sfxMimeType; + $value['mimeType'] = strtoupper($sfxMimeType); + } + case 'TEXT/X-VCARD': + case 'TEXT/VCARD': + case 'TEXT/CALENDAR': + case 'TEXT/X-VCALENDAR': + $linkData = array + ( + 'menuaction' => 'mail.mail_ui.getAttachment', + 'id' => $rowID, + 'part' => $value['partID'], + 'is_winmail' => $value['is_winmail'], + 'mailbox' => base64_encode($mailbox), + ); + $windowName = 'displayAttachment_'. $uid; + $reg = '800x600'; + // handle calendar/vcard + if (strtoupper($value['mimeType'])=='TEXT/CALENDAR') + { + $windowName = 'displayEvent_'. $rowID; + $reg2 = egw_link::get_registry('calendar','view_popup'); + } + if (strtoupper($value['mimeType'])=='TEXT/X-VCARD' || strtoupper($value['mimeType'])=='TEXT/VCARD') + { + $windowName = 'displayContact_'. $rowID; + $reg2 = egw_link::get_registry('addressbook','add_popup'); + } + // apply to action + list($width,$height) = explode('x',(!empty($reg2) ? $reg2 : $reg)); + $linkView = "egw_openWindowCentered('".$GLOBALS['egw']->link('/index.php',$linkData)."','$windowName',$width,$height);"; + break; + default: + $linkData = array + ( + 'menuaction' => 'mail.mail_ui.getAttachment', + 'id' => $rowID, + 'part' => $value['partID'], + 'is_winmail' => $value['is_winmail'], + 'mailbox' => base64_encode($mailbox), + ); + $linkView = "window.location.href = '".$GLOBALS['egw']->link('/index.php',$linkData)."';"; + break; + } + //error_log(__METHOD__.__LINE__.$linkView); + $attachmentHTML[$key]['link_view'] = ''. + ($value['name'] ? ( $filename ? $filename : $value['name'] ) : lang('(no subject)')). + ''; + + $linkData = array + ( + 'menuaction' => 'mail.mail_ui.getAttachment', + 'mode' => 'save', + 'id' => $rowID, + 'part' => $value['partID'], + 'is_winmail' => $value['is_winmail'], + 'mailbox' => base64_encode($mailbox), + ); + $attachmentHTML[$key]['link_save'] ="link('/index.php',$linkData)."' title='".$attachmentHTML[$key]['filename']."'>".html::image('felamimail','fileexport').""; + + if ($GLOBALS['egw_info']['user']['apps']['filemanager']) + { + $link_vfs_save = egw::link('/index.php',array( + 'menuaction' => 'filemanager.filemanager_select.select', + 'mode' => 'saveas', + 'name' => $value['name'], + 'mime' => strtolower($value['mimeType']), + 'method' => 'felamimail.uidisplay.vfsSaveAttachment', + 'id' => $mailbox.'::'.$uid.'::'.$value['partID'].'::'.$value['is_winmail'], + 'label' => lang('Save'), + )); + $vfs_save = "$url_img_vfs"; + // add save-all icon for first attachment + if (!$key && count($attachments) > 1) + { + foreach ($attachments as $ikey => $value) + { + //$rowID + $ids["id[$ikey]"] = $rowID.'::'.$value['partID'].'::'.$value['is_winmail'].'::'.$value['name']; + } + $link_vfs_save = egw::link('/index.php',array( + 'menuaction' => 'filemanager.filemanager_select.select', + 'mode' => 'select-dir', + 'method' => 'mail.mail_ui.vfsSaveAttachment', + 'label' => lang('Save all'), + )+$ids); + $vfs_save .= "$url_img_vfs_save_all"; + } + $attachmentHTML[$key]['link_save'] .= $vfs_save; + //error_log(__METHOD__.__LINE__.$attachmentHTML[$key]['link_save']); + } + } + $attachmentHTMLBlock=""; + foreach ((array)$attachmentHTML as $row) + { + $attachmentHTMLBlock .= "'; + $attachmentHTMLBlock .= "'; + $attachmentHTMLBlock .= "'; + $attachmentHTMLBlock .= "'; + } + $attachmentHTMLBlock .= "
".$row['link_view'].'".$row['mimetype'].'".$row['size'].'".$row['link_save'].'
"; + } + return $attachmentHTMLBlock; + } + /** * display image * diff --git a/mail/js/app.js b/mail/js/app.js index 09f1043e67..473cab2a7b 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -65,7 +65,12 @@ app.mail = AppJS.extend( this.et2 = et2.widgetContainer; var isMainView = false; - for (var t in et2.templates) if (t=='mail.index') {isMainView=true;break;}; + var isDisplay = false; + for (var t in et2.templates) + { + if (t=='mail.index') {isMainView=true;break;}; + if (t=='mail.display') {isDisplay=true;break;}; + } if (isMainView) this.mail_disablePreviewArea(true); }, diff --git a/mail/templates/default/app.css b/mail/templates/default/app.css index 67a2bf19e0..0d8a2f6f52 100644 --- a/mail/templates/default/app.css +++ b/mail/templates/default/app.css @@ -351,6 +351,7 @@ input[type=button] { -moz-opacity:1: filter: Alpha(opacity=100); } +/* #divGenTime { background-color:#efefdf; max-height: 10%; @@ -364,6 +365,7 @@ input[type=button] { -moz-opacity:1: filter: Alpha(opacity=100); } +*/ .mailDisplayHeaders { overflow: hidden; }