provide a more presentable attachment section

This commit is contained in:
Klaus Leithoff 2013-06-17 14:25:20 +00:00
parent 079b919bbe
commit 9c2ff7cf80
4 changed files with 195 additions and 170 deletions

View File

@ -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) // 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); $userPrefs = $this->mergeUserAndProfilePrefs($userPreferences,$profileData,$profileID);
$profileData->setPreferences($userPrefs); $profileData->setPreferences($userPrefs);

View File

@ -1511,15 +1511,58 @@ unset($query['actions']);
$fetchEmbeddedImages = false; $fetchEmbeddedImages = false;
if ($htmlOptions !='always_display') $fetchEmbeddedImages = true; if ($htmlOptions !='always_display') $fetchEmbeddedImages = true;
$attachments = $this->mail_bo->getMessageAttachments($uid, $partID, '',$fetchEmbeddedImages); $attachments = $this->mail_bo->getMessageAttachments($uid, $partID, '',$fetchEmbeddedImages);
//_debug_array($headers); //_debug_array($headers);
// attachments $attachmentHTMLBlock = self::createAttachmentBlock($attachments, $rowID, $uid, $mailbox);
/* if(is_array($attachments) && count($attachments) > 0 && count($attachments) > 4) { $webserverURL = $GLOBALS['egw_info']['server']['webserver_url'];
// 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'); $nonDisplayAbleCharacters = array('[\016]','[\017]',
} else { '[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
$this->t->set_var('attachment_div_height',''); // app.css bodyDIVAttachment '[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
}
#print "<pre>";print_r($rawheaders);print"</pre>";exit;
$mailBody = $this->get_load_email_data($uid, $partID, $mailbox,false);
//error_log(__METHOD__.__LINE__.$mailBody);
$this->mail_bo->closeConnection();
$etpl = new etemplate_new('mail.display');
// Set cell attributes directly
/*
$etpl->set_cell_attribute('nm[foldertree]','actions', array(
'drop_move_mail' => array(
'type' => 'drop',
'acceptedTypes' => 'mail',
'icon' => 'move',
'caption' => 'Move to',
'onExecute' => 'javaScript:app.mail.mail_move'
),
));
*/ */
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("<br>",$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) { if (is_array($attachments) && count($attachments) > 0) {
$url_img_vfs = html::image('filemanager','navbar', lang('Filemanager'), ' height="16"'); $url_img_vfs = html::image('filemanager','navbar', lang('Filemanager'), ' height="16"');
$url_img_vfs_save_all = html::image('felamimail','save_all', lang('Save all')); $url_img_vfs_save_all = html::image('felamimail','save_all', lang('Save all'));
@ -1527,19 +1570,18 @@ unset($query['actions']);
$detectedCharSet=$charset2use=mail_bo::$displayCharset; $detectedCharSet=$charset2use=mail_bo::$displayCharset;
foreach ($attachments as $key => $value) foreach ($attachments as $key => $value)
{ {
//_debug_array($value); //_debug_array($value);
#$detectedCharSet = mb_detect_encoding($value['name'].'a',strtoupper($this->displayCharset).",UTF-8, ISO-8559-1"); #$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 (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";}; //if (mb_convert_variables("ISO-8859-1","UTF-8",$value['name'])){echo "Juhu utf8 2 ISO\n";};
//echo $value['name']."\n"; //echo $value['name']."\n";
$filename=htmlentities($value['name'], ENT_QUOTES, $detectedCharSet); $filename=htmlentities($value['name'], ENT_QUOTES, $detectedCharSet);
/*
$this->t->set_var('row_color',$this->rowColor[($key+1)%2]); $attachmentHTML[$key]['filename']= ($value['name'] ? ( $filename ? $filename : $value['name'] ) : lang('(no subject)'));
$this->t->set_var('filename',($value['name'] ? ( $filename ? $filename : $value['name'] ) : lang('(no subject)'))); $attachmentHTML[$key]['mimetype']=mime_magic::mime2label($value['mimeType']);
$this->t->set_var('mimetype',mime_magic::mime2label($value['mimeType'])); $attachmentHTML[$key]['size']=egw_vfs::hsize($value['size']);
$this->t->set_var('size',egw_vfs::hsize($value['size'])); $attachmentHTML[$key]['attachment_number']=$key;
$this->t->set_var('attachment_number',$key);
*/
switch(strtoupper($value['mimeType'])) switch(strtoupper($value['mimeType']))
{ {
case 'MESSAGE/RFC822': case 'MESSAGE/RFC822':
@ -1613,12 +1655,10 @@ unset($query['actions']);
$linkView = "window.location.href = '".$GLOBALS['egw']->link('/index.php',$linkData)."';"; $linkView = "window.location.href = '".$GLOBALS['egw']->link('/index.php',$linkData)."';";
break; break;
} }
error_log(__METHOD__.__LINE__.$linkView); //error_log(__METHOD__.__LINE__.$linkView);
$attachmentHTML[] = '<a href="#" onclick="'.$linkView.' return false;"><b>'. $attachmentHTML[$key]['link_view'] = '<a href="#" onclick="'.$linkView.' return false;"><b>'.
($value['name'] ? ( $filename ? $filename : $value['name'] ) : lang('(no subject)')). ($value['name'] ? ( $filename ? $filename : $value['name'] ) : lang('(no subject)')).
'</b></a>'; '</b></a>';
// $this->t->set_var("link_view",$linkView);
// $this->t->set_var("target",$target);
$linkData = array $linkData = array
( (
@ -1629,7 +1669,7 @@ error_log(__METHOD__.__LINE__.$linkView);
'is_winmail' => $value['is_winmail'], 'is_winmail' => $value['is_winmail'],
'mailbox' => base64_encode($mailbox), 'mailbox' => base64_encode($mailbox),
); );
//$this->t->set_var("link_save",$GLOBALS['egw']->link('/index.php',$linkData)); $attachmentHTML[$key]['link_save'] ="<a href='".$GLOBALS['egw']->link('/index.php',$linkData)."' title='".$attachmentHTML[$key]['filename']."'>".html::image('felamimail','fileexport')."</a>";
if ($GLOBALS['egw_info']['user']['apps']['filemanager']) if ($GLOBALS['egw_info']['user']['apps']['filemanager'])
{ {
@ -1646,10 +1686,10 @@ error_log(__METHOD__.__LINE__.$linkView);
// add save-all icon for first attachment // add save-all icon for first attachment
if (!$key && count($attachments) > 1) if (!$key && count($attachments) > 1)
{ {
foreach ($attachments as $key => $value) foreach ($attachments as $ikey => $value)
{ {
//$rowID //$rowID
$ids["id[$key]"] = $rowID.'::'.$value['partID'].'::'.$value['is_winmail'].'::'.$value['name']; $ids["id[$ikey]"] = $rowID.'::'.$value['partID'].'::'.$value['is_winmail'].'::'.$value['name'];
} }
$link_vfs_save = egw::link('/index.php',array( $link_vfs_save = egw::link('/index.php',array(
'menuaction' => 'filemanager.filemanager_select.select', 'menuaction' => 'filemanager.filemanager_select.select',
@ -1657,55 +1697,23 @@ error_log(__METHOD__.__LINE__.$linkView);
'method' => 'mail.mail_ui.vfsSaveAttachment', 'method' => 'mail.mail_ui.vfsSaveAttachment',
'label' => lang('Save all'), 'label' => lang('Save all'),
)+$ids); )+$ids);
$vfs_save .= "\n<a href='#' onclick=\"egw_openWindowCentered('$link_vfs_save','vfs_save_attachment','640','530',window.outerWidth/2,window.outerHeight/2); return false;\">$url_img_vfs_save_all</a>"; $vfs_save .= "<a href='#' onclick=\"egw_openWindowCentered('$link_vfs_save','vfs_save_attachment','640','530',window.outerWidth/2,window.outerHeight/2); return false;\">$url_img_vfs_save_all</a>";
} }
//$this->t->set_var('vfs_save',$vfs_save); $attachmentHTML[$key]['link_save'] .= $vfs_save;
//error_log(__METHOD__.__LINE__.$attachmentHTML[$key]['link_save']);
} }
else }
$attachmentHTMLBlock="<table width='100%'>";
foreach ((array)$attachmentHTML as $row)
{ {
//$this->t->set_var('vfs_save',''); $attachmentHTMLBlock .= "<tr><td>".$row['link_view'].'</td>';
$attachmentHTMLBlock .= "<td>".$row['mimetype'].'</td>';
$attachmentHTMLBlock .= "<td>".$row['size'].'</td>';
$attachmentHTMLBlock .= "<td>".$row['link_save'].'</td></tr>';
} }
//$this->t->parse('attachment_rows','message_attachement_row',True); $attachmentHTMLBlock .= "</table>";
} }
} else { return $attachmentHTMLBlock;
//$this->t->set_var('attachment_rows','');
}
$webserverURL = $GLOBALS['egw_info']['server']['webserver_url'];
$nonDisplayAbleCharacters = array('[\016]','[\017]',
'[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
#print "<pre>";print_r($rawheaders);print"</pre>";exit;
$mailBody = $this->get_load_email_data($uid, $partID, $mailbox,false);
//error_log(__METHOD__.__LINE__.$mailBody);
$this->mail_bo->closeConnection();
$etpl = new etemplate_new('mail.display');
// Set cell attributes directly
/*
$etpl->set_cell_attribute('nm[foldertree]','actions', array(
'drop_move_mail' => array(
'type' => 'drop',
'acceptedTypes' => 'mail',
'icon' => 'move',
'caption' => 'Move to',
'onExecute' => 'javaScript:app.mail.mail_move'
),
));
*/
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("<br>",$error_msg):$error_msg);
$content['mail_displaysubject'] = $subject;
$content['mail_displaybody'] = $mailBody;
//_debug_array($attachments);
$content['mail_displayattachments'] = (count($attachments)?implode('<br>',$attachmentHTML):'');
$readonlys = $preserv = $content;
echo $etpl->exec('mail.mail_ui.displayMessage',$content,$sel_options,$readonlys,$preserv,2);
} }
/** /**

View File

@ -65,7 +65,12 @@ app.mail = AppJS.extend(
this.et2 = et2.widgetContainer; this.et2 = et2.widgetContainer;
var isMainView = false; 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); if (isMainView) this.mail_disablePreviewArea(true);
}, },

View File

@ -351,6 +351,7 @@ input[type=button] {
-moz-opacity:1: -moz-opacity:1:
filter: Alpha(opacity=100); filter: Alpha(opacity=100);
} }
/*
#divGenTime { #divGenTime {
background-color:#efefdf; background-color:#efefdf;
max-height: 10%; max-height: 10%;
@ -364,6 +365,7 @@ input[type=button] {
-moz-opacity:1: -moz-opacity:1:
filter: Alpha(opacity=100); filter: Alpha(opacity=100);
} }
*/
.mailDisplayHeaders { .mailDisplayHeaders {
overflow: hidden; overflow: hidden;
} }