Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like mail_ui often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use mail_ui, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 36 | class mail_ui |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * Methods callable via menuaction |
||
| 40 | * |
||
| 41 | * @var array |
||
| 42 | */ |
||
| 43 | var $public_functions = array |
||
| 44 | ( |
||
| 45 | 'index' => True, |
||
| 46 | 'displayHeader' => True, |
||
| 47 | 'displayMessage' => True, |
||
| 48 | 'displayImage' => True, |
||
| 49 | 'getAttachment' => True, |
||
| 50 | 'download_zip' => True, |
||
| 51 | 'saveMessage' => True, |
||
| 52 | 'vfsSaveAttachment' => True, |
||
| 53 | 'vfsSaveMessage' => True, |
||
| 54 | 'loadEmailBody' => True, |
||
| 55 | 'importMessage' => True, |
||
| 56 | 'importMessageFromVFS2DraftAndDisplay'=>True, |
||
| 57 | 'subscription' => True, |
||
| 58 | 'folderManagement' => true, |
||
| 59 | ); |
||
| 60 | |||
| 61 | /** |
||
| 62 | * current icServerID |
||
| 63 | * |
||
| 64 | * @var int |
||
| 65 | */ |
||
| 66 | static $icServerID; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * delimiter - used to separate profileID from foldertreestructure, and separate keyinformation in rowids |
||
| 70 | * |
||
| 71 | * @var string |
||
| 72 | */ |
||
| 73 | static $delimiter = '::'; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * nextMatch name for index |
||
| 77 | * |
||
| 78 | * @var string |
||
| 79 | */ |
||
| 80 | static $nm_index = 'nm'; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * instance of Mail |
||
| 84 | * |
||
| 85 | * @var Mail |
||
| 86 | */ |
||
| 87 | var $mail_bo; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * definition of available / supported search types |
||
| 91 | * |
||
| 92 | * @var array |
||
| 93 | */ |
||
| 94 | var $searchTypes = array( |
||
| 95 | 'quick' => 'quicksearch', // lang('quicksearch') |
||
| 96 | 'quickwithcc'=> 'quicksearch (with cc)', // lang('quicksearch (with cc)') |
||
| 97 | 'subject' => 'subject', // lang('subject') |
||
| 98 | 'body' => 'message body', // lang('message body') |
||
| 99 | 'from' => 'from', // lang('from') |
||
| 100 | 'to' => 'to', // lang('to') |
||
| 101 | 'cc' => 'cc', // lang('cc') |
||
| 102 | 'text' => 'whole message', // lang('whole message') |
||
| 103 | 'larger' => 'greater than', // lang('greater than') |
||
| 104 | 'smaller' => 'less than', // lang('less than') |
||
| 105 | 'bydate' => 'Selected date range (with quicksearch)',// lang('Selected date range (with quicksearch)') |
||
| 106 | ); |
||
| 107 | |||
| 108 | /** |
||
| 109 | * definition of available / supported status types |
||
| 110 | * |
||
| 111 | * @var array |
||
| 112 | */ |
||
| 113 | var $statusTypes = array( |
||
| 114 | 'any' => 'any status',// lang('any status') |
||
| 115 | 'flagged' => 'flagged', // lang('flagged') |
||
| 116 | 'unseen' => 'unread', // lang('unread') |
||
| 117 | 'answered' => 'replied', // lang('replied') |
||
| 118 | 'seen' => 'read', // lang('read') |
||
| 119 | 'deleted' => 'deleted', // lang('deleted') |
||
| 120 | ); |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Constructor |
||
| 124 | * |
||
| 125 | * @param boolean $run_constructor =true false: no not run constructor and therefore do NOT connect to imap server |
||
| 126 | */ |
||
| 127 | function __construct($run_constructor=true) |
||
| 128 | { |
||
| 129 | $this->mail_tree = new mail_tree($this); |
||
| 130 | if (!$run_constructor) return; |
||
| 131 | |||
| 132 | if (Mail::$debugTimes) $starttime = microtime (true); |
||
| 133 | // no autohide of the sidebox, as we use it for folderlist now. |
||
| 134 | unset($GLOBALS['egw_info']['user']['preferences']['common']['auto_hide_sidebox']); |
||
| 135 | |||
| 136 | View Code Duplication | if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']) && !empty($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'])) |
|
| 137 | { |
||
| 138 | self::$icServerID = (int)$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']; |
||
| 139 | } |
||
| 140 | if ($_GET["resetConnection"]) |
||
| 141 | { |
||
| 142 | unset($_GET["resetConnection"]); |
||
| 143 | if (Mail::$debug) error_log(__METHOD__.__LINE__.' Connection Reset triggered: for Profile with ID:'.self::$icServerID); |
||
| 144 | Mail::unsetCachedObjects(self::$icServerID); |
||
| 145 | } |
||
| 146 | |||
| 147 | try { |
||
| 148 | $this->mail_bo = Mail::getInstance(true,self::$icServerID, true, false, true); |
||
| 149 | View Code Duplication | if (Mail::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace()); |
|
| 150 | //error_log(__METHOD__.__LINE__.array2string($this->mail_bo->icServer)); |
||
| 151 | |||
| 152 | // RegEx to minimize extra openConnection |
||
| 153 | $needle = '/^(?!mail)/'; |
||
| 154 | if (!preg_match($needle,$_GET['menuaction']) && !Api\Json\Request::isJSONRequest()) |
||
| 155 | { |
||
| 156 | //error_log(__METHOD__.__LINE__.' Fetched IC Server openConnection:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace()); |
||
| 157 | //openConnection gathers SpecialUseFolderInformation and Delimiter Info |
||
| 158 | $this->mail_bo->openConnection(self::$icServerID); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | catch (Exception $e) |
||
| 162 | { |
||
| 163 | // we need this to handle failed JSONRequests |
||
| 164 | if (Api\Json\Request::isJSONRequest() && $_GET['menuaction'] != 'mail.mail_ui.index') |
||
| 165 | { |
||
| 166 | $response = Api\Json\Response::get(); |
||
| 167 | $response->call('egw.message',$e->getMessage(),'error'); |
||
| 168 | } |
||
| 169 | // redirect to mail wizard to handle it (redirect works for ajax too), unless index is called. we want the sidebox |
||
| 170 | if ($_GET['menuaction'] != 'mail.mail_ui.index') self::callWizard($e->getMessage(),true,'error',false); |
||
| 171 | } |
||
| 172 | if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__); |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * callWizard |
||
| 177 | * |
||
| 178 | * @param string $message |
||
| 179 | * @param boolean $exit If true, will call exit() after opening the wizardpopup |
||
| 180 | * @param string $msg_type = 'success' message type |
||
| 181 | */ |
||
| 182 | static function callWizard($message, $exit=true, $msg_type='success',$reset_sidebox_on_index=true) |
||
| 183 | { |
||
| 184 | //error_log(__METHOD__."('$message', $exit) ".function_backtrace()); |
||
| 185 | $linkData=(self::$icServerID ? array( |
||
| 186 | 'menuaction' => 'mail.mail_wizard.edit', |
||
| 187 | 'acc_id' => self::$icServerID, |
||
| 188 | ) : array( |
||
| 189 | 'menuaction' => 'mail.mail_wizard.add', |
||
| 190 | )) + array( |
||
| 191 | 'msg' => $message, |
||
| 192 | 'msg_type' => $msg_type |
||
| 193 | ); |
||
| 194 | |||
| 195 | if (Api\Json\Response::isJSONResponse()) |
||
| 196 | { |
||
| 197 | $response = Api\Json\Response::get(); |
||
| 198 | $windowName = "editMailAccount".self::$icServerID; |
||
| 199 | $response->call("egw.open_link", Egw::link('/index.php', $linkData), $windowName, "600x480",null,true); |
||
| 200 | Framework::message($message, 'error'); |
||
| 201 | if ($_GET['menuaction'] == 'mail.mail_ui.index' && $reset_sidebox_on_index) |
||
| 202 | { |
||
| 203 | $response->call('framework.setSidebox','mail',array(),'md5'); |
||
| 204 | } |
||
| 205 | if ($exit) |
||
| 206 | { |
||
| 207 | exit(); |
||
| 208 | } |
||
| 209 | } |
||
| 210 | else // regular GET request eg. in idots template |
||
| 211 | { |
||
| 212 | $windowName = "editMailAccount".self::$icServerID; |
||
| 213 | Framework::popup(Framework::link('/index.php',$linkData),$windowName); |
||
| 214 | $GLOBALS['egw']->framework->render($message,'',true); |
||
| 215 | if ($exit) |
||
| 216 | { |
||
| 217 | exit(); |
||
| 218 | } |
||
| 219 | } |
||
| 220 | } |
||
| 221 | |||
| 222 | /** |
||
| 223 | * changeProfile |
||
| 224 | * |
||
| 225 | * @param int $_icServerID |
||
| 226 | * @param boolean $unsetCache |
||
| 227 | * |
||
| 228 | * @throws Api\Exception |
||
| 229 | */ |
||
| 230 | function changeProfile($_icServerID,$unsetCache=false) |
||
| 231 | { |
||
| 232 | if (Mail::$debugTimes) $starttime = microtime (true); |
||
| 233 | if (self::$icServerID != $_icServerID) |
||
| 234 | { |
||
| 235 | self::$icServerID = $_icServerID; |
||
| 236 | } |
||
| 237 | if (Mail::$debug) error_log(__METHOD__.__LINE__.'->'.self::$icServerID.'<->'.$_icServerID); |
||
| 238 | |||
| 239 | if ($unsetCache) Mail::unsetCachedObjects(self::$icServerID); |
||
| 240 | $this->mail_bo = Mail::getInstance(false,self::$icServerID,true, false, true); |
||
| 241 | View Code Duplication | if (Mail::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace()); |
|
| 242 | // no icServer Object: something failed big time |
||
| 243 | if (!isset($this->mail_bo) || !isset($this->mail_bo->icServer) || $this->mail_bo->icServer->ImapServerId<>$_icServerID) |
||
| 244 | { |
||
| 245 | self::$icServerID = $_icServerID; |
||
| 246 | throw new Api\Exception('Profile change failed!'); |
||
| 247 | } |
||
| 248 | |||
| 249 | // save session varchar |
||
| 250 | $oldicServerID =& Api\Cache::getSession('mail','activeProfileID'); |
||
| 251 | if ($oldicServerID <> self::$icServerID) $this->mail_bo->openConnection(self::$icServerID); |
||
| 252 | if (true) $oldicServerID = self::$icServerID; |
||
| 253 | if (!Mail::storeActiveProfileIDToPref($this->mail_bo->icServer, self::$icServerID, true )) |
||
|
|
|||
| 254 | { |
||
| 255 | throw new Api\Exception(__METHOD__." failed to change Profile to $_icServerID"); |
||
| 256 | } |
||
| 257 | |||
| 258 | if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__); |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Ajax function to request next branch of a tree branch |
||
| 263 | */ |
||
| 264 | static function ajax_tree_autoloading ($_id = null) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Subscription popup window |
||
| 273 | * |
||
| 274 | * @param array $content |
||
| 275 | * @param type $msg |
||
| 276 | */ |
||
| 277 | function subscription(array $content=null ,$msg=null) |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Main mail page |
||
| 415 | * |
||
| 416 | * @param array $content |
||
| 417 | * @param string $msg |
||
| 418 | */ |
||
| 419 | function index(array $content=null,$msg=null) |
||
| 420 | { |
||
| 421 | //error_log(__METHOD__.__LINE__.array2string($content)); |
||
| 422 | try { |
||
| 423 | if (!isset($this->mail_bo)) throw new Api\Exception\WrongUserinput(lang('Initialization of mail failed. Please use the Wizard to cope with the problem.')); |
||
| 424 | //error_log(__METHOD__.__LINE__.function_backtrace()); |
||
| 425 | if (Mail::$debugTimes) $starttime = microtime (true); |
||
| 426 | $this->mail_bo->restoreSessionData(); |
||
| 427 | $sessionFolder = $this->mail_bo->sessionData['mailbox']; |
||
| 428 | if ($this->mail_bo->folderExists($sessionFolder)) |
||
| 429 | { |
||
| 430 | $this->mail_bo->reopen($sessionFolder); // needed to fetch full set of capabilities |
||
| 431 | } |
||
| 432 | else |
||
| 433 | { |
||
| 434 | $sessionFolder = $this->mail_bo->sessionData['mailbox'] = 'INBOX'; |
||
| 435 | } |
||
| 436 | //error_log(__METHOD__.__LINE__.' SessionFolder:'.$sessionFolder.' isToSchema:'.$toSchema); |
||
| 437 | if (!is_array($content)) |
||
| 438 | { |
||
| 439 | $content = array( |
||
| 440 | self::$nm_index => Api\Cache::getSession('mail', 'index'), |
||
| 441 | ); |
||
| 442 | if (!is_array($content[self::$nm_index])) |
||
| 443 | { |
||
| 444 | // These only set on first load |
||
| 445 | $content[self::$nm_index] = array( |
||
| 446 | 'filter' => 'any', // filter is used to choose the mailbox |
||
| 447 | 'lettersearch' => false, // I show a lettersearch |
||
| 448 | 'searchletter' => false, // I0 active letter of the lettersearch or false for [all] |
||
| 449 | 'start' => 0, // IO position in list |
||
| 450 | 'order' => 'date', // IO name of the column to sort after (optional for the sortheaders) |
||
| 451 | 'sort' => 'DESC', // IO direction of the sort: 'ASC' or 'DESC' |
||
| 452 | ); |
||
| 453 | } |
||
| 454 | if (Api\Header\UserAgent::mobile()) $content[self::$nm_index]['header_row'] = 'mail.index.header_right'; |
||
| 455 | } |
||
| 456 | |||
| 457 | // These must always be set, even if $content is an array |
||
| 458 | $content[self::$nm_index]['cat_is_select'] = true; // Category select is just a normal selectbox |
||
| 459 | $content[self::$nm_index]['no_filter2'] = false; // Disable second filter |
||
| 460 | $content[self::$nm_index]['actions'] = self::get_actions(); |
||
| 461 | $content[self::$nm_index]['row_id'] = 'row_id'; // is a concatenation of trim($GLOBALS['egw_info']['user']['account_id']):profileID:base64_encode(FOLDERNAME):uid |
||
| 462 | $content[self::$nm_index]['placeholder_actions'] = array('composeasnew'); |
||
| 463 | $content[self::$nm_index]['get_rows'] = 'mail_ui::get_rows'; |
||
| 464 | $content[self::$nm_index]['num_rows'] = 0; // Do not send any rows with initial request |
||
| 465 | $content[self::$nm_index]['default_cols'] = 'status,attachments,subject,address,date,size'; // I columns to use if there's no user or default pref (! as first char uses all but the named columns), default all columns |
||
| 466 | $content[self::$nm_index]['csv_fields'] = false; |
||
| 467 | if ($msg) |
||
| 468 | { |
||
| 469 | $content['msg'] = $msg; |
||
| 470 | } |
||
| 471 | else |
||
| 472 | { |
||
| 473 | unset($msg); |
||
| 474 | unset($content['msg']); |
||
| 475 | } |
||
| 476 | // call getQuotaRoot asynchronously in getRows by initiating a client Server roundtrip |
||
| 477 | $quota = false;//$this->mail_bo->getQuotaRoot(); |
||
| 478 | if($quota !== false && $quota['limit'] != 'NOT SET') { |
||
| 479 | $quotainfo = $this->quotaDisplay($quota['usage'], $quota['limit']); |
||
| 480 | $content[self::$nm_index]['quota'] = $sel_options[self::$nm_index]['quota'] = $quotainfo['text']; |
||
| 481 | $content[self::$nm_index]['quotainpercent'] = $sel_options[self::$nm_index]['quotainpercent'] = (string)$quotainfo['percent']; |
||
| 482 | $content[self::$nm_index]['quotaclass'] = $sel_options[self::$nm_index]['quotaclass'] = $quotainfo['class']; |
||
| 483 | $content[self::$nm_index]['quotanotsupported'] = $sel_options[self::$nm_index]['quotanotsupported'] = ""; |
||
| 484 | } else { |
||
| 485 | $content[self::$nm_index]['quota'] = $sel_options[self::$nm_index]['quota'] = lang("Quota not provided by server"); |
||
| 486 | $content[self::$nm_index]['quotaclass'] = $sel_options[self::$nm_index]['quotaclass'] = "mail_DisplayNone"; |
||
| 487 | $content[self::$nm_index]['quotanotsupported'] = $sel_options[self::$nm_index]['quotanotsupported'] = "mail_DisplayNone"; |
||
| 488 | } |
||
| 489 | // call gatherVacation asynchronously in getRows by initiating a client Server roundtrip |
||
| 490 | $vacation = false;//$this->gatherVacation(); |
||
| 491 | //error_log(__METHOD__.__LINE__.' Server:'.self::$icServerID.' Sieve Enabled:'.array2string($vacation)); |
||
| 492 | if($vacation) { |
||
| 493 | if (is_array($vacation) && ($vacation['status'] == 'on' || $vacation['status']=='by_date' && $vacation['end_date'] > time())) |
||
| 494 | { |
||
| 495 | $dtfrmt = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']/*.' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat']!='24'?'h:i a':'H:i')*/; |
||
| 496 | $content[self::$nm_index]['vacationnotice'] = $sel_options[self::$nm_index]['vacationnotice'] = lang('Vacation notice is active'); |
||
| 497 | $content[self::$nm_index]['vacationrange'] = $sel_options[self::$nm_index]['vacationrange'] = ($vacation['status']=='by_date'? Api\DateTime::server2user($vacation['start_date'],$dtfrmt,true).($vacation['end_date']>$vacation['start_date']?'->'.Api\DateTime::server2user($vacation['end_date']+ 24*3600-1,$dtfrmt,true):''):''); |
||
| 498 | } |
||
| 499 | } |
||
| 500 | if ($vacation==false) |
||
| 501 | { |
||
| 502 | $content[self::$nm_index]['vacationnotice'] = $sel_options[self::$nm_index]['vacationnotice'] = ''; |
||
| 503 | $content[self::$nm_index]['vacationrange'] = $sel_options[self::$nm_index]['vacationrange'] = ''; |
||
| 504 | } |
||
| 505 | //$zstarttime = microtime (true); |
||
| 506 | $sel_options[self::$nm_index]['foldertree'] = $this->mail_tree->getInitialIndexTree(null, $this->mail_bo->profileID, null, !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'],!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']); |
||
| 507 | //$zendtime = microtime(true) - $zstarttime; |
||
| 508 | //error_log(__METHOD__.__LINE__. " time used: ".$zendtime); |
||
| 509 | $content[self::$nm_index]['selectedFolder'] = $this->mail_bo->profileID.self::$delimiter.(!empty($this->mail_bo->sessionData['mailbox'])?$this->mail_bo->sessionData['mailbox']:'INBOX'); |
||
| 510 | // since we are connected,(and selected the folder) we check for capabilities SUPPORTS_KEYWORDS to eventually add the keyword filters |
||
| 511 | View Code Duplication | if ( $this->mail_bo->icServer->hasCapability('SUPPORTS_KEYWORDS')) |
|
| 512 | { |
||
| 513 | $this->statusTypes = array_merge($this->statusTypes,array( |
||
| 514 | 'keyword1' => 'important',//lang('important'), |
||
| 515 | 'keyword2' => 'job', //lang('job'), |
||
| 516 | 'keyword3' => 'personal',//lang('personal'), |
||
| 517 | 'keyword4' => 'to do', //lang('to do'), |
||
| 518 | 'keyword5' => 'later', //lang('later'), |
||
| 519 | )); |
||
| 520 | } |
||
| 521 | else |
||
| 522 | { |
||
| 523 | $keywords = array('keyword1','keyword2','keyword3','keyword4','keyword5'); |
||
| 524 | foreach($keywords as &$k) |
||
| 525 | { |
||
| 526 | if (array_key_exists($k,$this->statusTypes)) unset($this->statusTypes[$k]); |
||
| 527 | } |
||
| 528 | } |
||
| 529 | |||
| 530 | View Code Duplication | if (!isset($content[self::$nm_index]['foldertree'])) $content[self::$nm_index]['foldertree'] = $this->mail_bo->profileID.self::$delimiter.'INBOX'; |
|
| 531 | View Code Duplication | if (!isset($content[self::$nm_index]['selectedFolder'])) $content[self::$nm_index]['selectedFolder'] = $this->mail_bo->profileID.self::$delimiter.'INBOX'; |
|
| 532 | |||
| 533 | $content[self::$nm_index]['foldertree'] = $content[self::$nm_index]['selectedFolder']; |
||
| 534 | |||
| 535 | if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) |
||
| 536 | { |
||
| 537 | Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10); |
||
| 538 | if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID]=true; |
||
| 539 | } |
||
| 540 | View Code Duplication | if (!Mail::$supportsORinQuery[$this->mail_bo->profileID]) |
|
| 541 | { |
||
| 542 | unset($this->searchTypes['quick']); |
||
| 543 | unset($this->searchTypes['quickwithcc']); |
||
| 544 | } |
||
| 545 | $sel_options['cat_id'] = $this->searchTypes; |
||
| 546 | //error_log(__METHOD__.__LINE__.array2string($sel_options['cat_id'])); |
||
| 547 | //error_log(__METHOD__.__LINE__.array2string($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType'])); |
||
| 548 | $content[self::$nm_index]['cat_id'] = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType']; |
||
| 549 | $sel_options['filter'] = $this->statusTypes; |
||
| 550 | $sel_options['filter2'] = array(''=>lang('No Sneak Preview in list'),1=>lang('Sneak Preview in list')); |
||
| 551 | $content[self::$nm_index]['filter2'] = $GLOBALS['egw_info']['user']['preferences']['mail']['ShowDetails']; |
||
| 552 | |||
| 553 | $etpl = new Etemplate('mail.index'); |
||
| 554 | //apply infolog_filter_change javascript method (hide/show of date filter form) over onchange filter |
||
| 555 | $content[self::$nm_index]['cat_id_onchange'] = "app.mail.mail_searchtype_change()"; |
||
| 556 | // set the actions on tree |
||
| 557 | $etpl->setElementAttribute(self::$nm_index.'[foldertree]','actions', $this->get_tree_actions()); |
||
| 558 | |||
| 559 | // sending preview toolbar actions |
||
| 560 | if ($content['mailSplitter']) $etpl->setElementAttribute('mailPreview[toolbar]', 'actions', $this->get_toolbar_actions()); |
||
| 561 | |||
| 562 | // We need to send toolbar actions to client-side because view template needs them |
||
| 563 | if (Api\Header\UserAgent::mobile()) $sel_options['toolbar'] = $this->get_toolbar_actions(); |
||
| 564 | |||
| 565 | //we use the category "filter" option as specifier where we want to search (quick, subject, from, to, etc. ....) |
||
| 566 | if (empty($content[self::$nm_index]['cat_id']) || empty($content[self::$nm_index]['search'])) |
||
| 567 | { |
||
| 568 | $content[self::$nm_index]['cat_id']=($content[self::$nm_index]['cat_id']?(!Mail::$supportsORinQuery[$this->mail_bo->profileID]&&($content[self::$nm_index]['cat_id']=='quick'||$content[self::$nm_index]['cat_id']=='quickwithcc')?'subject':$content[self::$nm_index]['cat_id']):(Mail::$supportsORinQuery[$this->mail_bo->profileID]?'quick':'subject')); |
||
| 569 | } |
||
| 570 | $readonlys = $preserv = array(); |
||
| 571 | if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__); |
||
| 572 | } |
||
| 573 | catch (Exception $e) |
||
| 574 | { |
||
| 575 | // do not exit here. mail-tree should be build. if we exit here, we never get there. |
||
| 576 | error_log(__METHOD__.__LINE__.$e->getMessage().($e->details?', '.$e->details:'').' Menuaction:'.$_GET['menuaction'].'.'.function_backtrace()); |
||
| 577 | if (isset($this->mail_bo)) |
||
| 578 | { |
||
| 579 | if (empty($etpl)) |
||
| 580 | { |
||
| 581 | $sel_options[self::$nm_index]['foldertree'] = $this->mail_tree->getInitialIndexTree(null, $this->mail_bo->profileID, null, !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'],!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']); |
||
| 582 | $etpl = new Etemplate('mail.index'); |
||
| 583 | } |
||
| 584 | $etpl->setElementAttribute(self::$nm_index.'[foldertree]','actions', $this->get_tree_actions(false)); |
||
| 585 | } |
||
| 586 | $readonlys = $preserv = array(); |
||
| 587 | if (empty($content)) $content=array(); |
||
| 588 | |||
| 589 | self::callWizard($e->getMessage().($e->details?', '.$e->details:''),(isset($this->mail_bo)?false:true), 'error',false); |
||
| 590 | //return false; |
||
| 591 | } |
||
| 592 | // Check preview pane is enabled, then show splitter - preference used to be '1', now 'hide' |
||
| 593 | if ($this->mail_bo->mailPreferences['previewPane'] == '1' || $this->mail_bo->mailPreferences['previewPane'] == 'hide') |
||
| 594 | { |
||
| 595 | $etpl->setElementAttribute('splitter', 'template', 'mail.index.nosplitter'); |
||
| 596 | } |
||
| 597 | |||
| 598 | return $etpl->exec('mail.mail_ui.index',$content,$sel_options,$readonlys,$preserv); |
||
| 599 | } |
||
| 600 | |||
| 601 | /** |
||
| 602 | * Get tree actions / context menu for tree |
||
| 603 | * |
||
| 604 | * Changes here, may require to log out, as $content[self::$nm_index] get stored in session! |
||
| 605 | * @param {boolean} $imap_actions set to false if you want to avoid to talk to the imap-server |
||
| 606 | * @return array |
||
| 607 | */ |
||
| 608 | function get_tree_actions($imap_actions=true) |
||
| 609 | { |
||
| 610 | // Start at 2 so auto-added copy+paste actions show up as second group |
||
| 611 | // Needed because there's no 'select all' action to push things down |
||
| 612 | $group=1; |
||
| 613 | // Set tree actions |
||
| 614 | $tree_actions = array( |
||
| 615 | 'drop_move_mail' => array( |
||
| 616 | 'type' => 'drop', |
||
| 617 | 'acceptedTypes' => 'mail', |
||
| 618 | 'icon' => 'move', |
||
| 619 | 'caption' => 'Move to', |
||
| 620 | 'onExecute' => 'javaScript:app.mail.mail_move' |
||
| 621 | ), |
||
| 622 | 'drop_copy_mail' => array( |
||
| 623 | 'type' => 'drop', |
||
| 624 | 'acceptedTypes' => 'mail', |
||
| 625 | 'icon' => 'copy', |
||
| 626 | 'caption' => 'Copy to', |
||
| 627 | 'onExecute' => 'javaScript:app.mail.mail_copy' |
||
| 628 | ), |
||
| 629 | 'drop_cancel' => array( |
||
| 630 | 'icon' => 'cancel', |
||
| 631 | 'caption' => 'Cancel', |
||
| 632 | 'acceptedTypes' => 'mail', |
||
| 633 | 'type' => 'drop', |
||
| 634 | ), |
||
| 635 | 'drop_move_folder' => array( |
||
| 636 | 'caption' => 'Move folder', |
||
| 637 | 'hideOnDisabled' => true, |
||
| 638 | 'type' => 'drop', |
||
| 639 | 'acceptedTypes' => 'mailFolder', |
||
| 640 | 'onExecute' => 'javaScript:app.mail.mail_MoveFolder' |
||
| 641 | ), |
||
| 642 | // Tree does support this one |
||
| 643 | 'add' => array( |
||
| 644 | 'caption' => 'Add Folder', |
||
| 645 | 'onExecute' => 'javaScript:app.mail.mail_AddFolder', |
||
| 646 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 647 | 'group' => $group, |
||
| 648 | ), |
||
| 649 | 'edit' => array( |
||
| 650 | 'caption' => 'Rename Folder', |
||
| 651 | 'onExecute' => 'javaScript:app.mail.mail_RenameFolder', |
||
| 652 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 653 | 'group' => $group, |
||
| 654 | ), |
||
| 655 | 'move' => array( |
||
| 656 | 'caption' => 'Move Folder', |
||
| 657 | 'type' => 'drag', |
||
| 658 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 659 | 'dragType' => array('mailFolder'), |
||
| 660 | 'group' => $group, |
||
| 661 | ), |
||
| 662 | 'delete' => array( |
||
| 663 | 'caption' => 'Delete Folder', |
||
| 664 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 665 | 'onExecute' => 'javaScript:app.mail.mail_DeleteFolder', |
||
| 666 | 'group' => $group, |
||
| 667 | ), |
||
| 668 | 'subscribe' => array( |
||
| 669 | 'caption' => 'Subscribe folder ...', |
||
| 670 | //'icon' => 'configure', |
||
| 671 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 672 | 'onExecute' => 'javaScript:app.mail.edit_subscribe', |
||
| 673 | 'group' => $group |
||
| 674 | ), |
||
| 675 | 'unsubscribe' => array( |
||
| 676 | 'caption' => 'Unsubscribe folder', |
||
| 677 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 678 | 'onExecute' => 'javaScript:app.mail.unsubscribe_folder', |
||
| 679 | 'group' => $group, |
||
| 680 | ), |
||
| 681 | 'foldermanagement' => array( |
||
| 682 | 'caption' => 'Folder Management ...', |
||
| 683 | 'icon' => 'folder_management', |
||
| 684 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 685 | 'onExecute' => 'javaScript:app.mail.folderManagement', |
||
| 686 | 'group' => $group, |
||
| 687 | 'hideOnMobile' => true |
||
| 688 | ), |
||
| 689 | 'sieve' => array( |
||
| 690 | 'caption' => 'Mail filter', |
||
| 691 | 'onExecute' => 'javaScript:app.mail.edit_sieve', |
||
| 692 | |||
| 693 | 'enabled' => 'javaScript:app.mail.sieve_enabled', |
||
| 694 | 'icon' => 'mail/filter', // funnel |
||
| 695 | 'hideOnMobile' => true |
||
| 696 | ), |
||
| 697 | 'vacation' => array( |
||
| 698 | 'caption' => 'Vacation notice', |
||
| 699 | 'icon' => 'mail/navbar', // mail as in admin |
||
| 700 | 'onExecute' => 'javaScript:app.mail.edit_vacation', |
||
| 701 | 'enabled' => 'javaScript:app.mail.sieve_enabled', |
||
| 702 | ), |
||
| 703 | 'edit_account' => array( |
||
| 704 | 'caption' => 'Edit account ...', |
||
| 705 | 'icon' => 'configure', |
||
| 706 | 'onExecute' => 'javaScript:app.mail.edit_account', |
||
| 707 | ), |
||
| 708 | 'edit_acl' => array( |
||
| 709 | 'caption' => 'Edit folder ACL ...', |
||
| 710 | 'icon' => 'lock', |
||
| 711 | 'enabled' => 'javaScript:app.mail.acl_enabled', |
||
| 712 | 'onExecute' => 'javaScript:app.mail.edit_acl', |
||
| 713 | ), |
||
| 714 | ); |
||
| 715 | // the preference prefaskformove controls actually if there is a popup on target or not |
||
| 716 | // if there are multiple options there is a popup on target, 0 for prefaskformove means |
||
| 717 | // that only move is available; 1 stands for move and cancel; 2 (should be the default if |
||
| 718 | // not set); so we are assuming this, when not set |
||
| 719 | if (isset($this->mail_bo->mailPreferences['prefaskformove'])) |
||
| 720 | { |
||
| 721 | switch ($this->mail_bo->mailPreferences['prefaskformove']) |
||
| 722 | { |
||
| 723 | case 0: |
||
| 724 | unset($tree_actions['drop_copy_mail']); |
||
| 725 | unset($tree_actions['drop_cancel']); |
||
| 726 | break; |
||
| 727 | case 1: |
||
| 728 | unset($tree_actions['drop_copy_mail']); |
||
| 729 | break; |
||
| 730 | default: |
||
| 731 | // everything is fine |
||
| 732 | } |
||
| 733 | } |
||
| 734 | //error_log(__METHOD__.__LINE__.' showAllFoldersInFolderPane:'.$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'].'/'.$GLOBALS['egw_info']['user']['preferences']['mail']['showAllFoldersInFolderPane']); |
||
| 735 | if ($this->mail_bo->mailPreferences['showAllFoldersInFolderPane']) |
||
| 736 | { |
||
| 737 | unset($tree_actions['subscribe']); |
||
| 738 | unset($tree_actions['unsubscribe']); |
||
| 739 | } |
||
| 740 | ++$group; // put delete in own group |
||
| 741 | switch($GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions']) |
||
| 742 | { |
||
| 743 | case 'move_to_trash': |
||
| 744 | $tree_actions['empty_trash'] = array( |
||
| 745 | 'caption' => 'empty trash', |
||
| 746 | 'icon' => 'dhtmlxtree/MailFolderTrash', |
||
| 747 | 'onExecute' => 'javaScript:app.mail.mail_emptyTrash', |
||
| 748 | 'group' => $group, |
||
| 749 | ); |
||
| 750 | break; |
||
| 751 | case 'mark_as_deleted': |
||
| 752 | $tree_actions['compress_folder'] = array( |
||
| 753 | 'caption' => 'compress folder', |
||
| 754 | 'icon' => 'dhtmlxtree/MailFolderTrash', |
||
| 755 | 'onExecute' => 'javaScript:app.mail.mail_compressFolder', |
||
| 756 | 'group' => $group, |
||
| 757 | ); |
||
| 758 | break; |
||
| 759 | } |
||
| 760 | $junkFolder = ($imap_actions?$this->mail_bo->getJunkFolder():null); |
||
| 761 | |||
| 762 | //error_log(__METHOD__.__LINE__.$junkFolder); |
||
| 763 | if ($junkFolder && !empty($junkFolder)) |
||
| 764 | { |
||
| 765 | $tree_actions['empty_spam'] = array( |
||
| 766 | 'caption' => 'empty junk', |
||
| 767 | 'icon' => 'dhtmlxtree/MailFolderJunk', |
||
| 768 | 'enabled' => 'javaScript:app.mail.spamfolder_enabled', |
||
| 769 | 'onExecute' => 'javaScript:app.mail.mail_emptySpam', |
||
| 770 | 'group' => $group, |
||
| 771 | ); |
||
| 772 | } |
||
| 773 | $tree_actions['sieve']['group'] = $tree_actions['vacation']['group'] = ++$group; // new group for filter |
||
| 774 | $tree_actions['edit_account']['group'] = $tree_actions['edit_acl']['group'] = ++$group; |
||
| 775 | |||
| 776 | |||
| 777 | // enforce global (group-specific) ACL |
||
| 778 | if (!mail_hooks::access('aclmanagement')) |
||
| 779 | { |
||
| 780 | unset($tree_actions['edit_acl']); |
||
| 781 | } |
||
| 782 | if (!mail_hooks::access('editfilterrules')) |
||
| 783 | { |
||
| 784 | unset($tree_actions['sieve']); |
||
| 785 | } |
||
| 786 | if (!mail_hooks::access('absentnotice')) |
||
| 787 | { |
||
| 788 | unset($tree_actions['vacation']); |
||
| 789 | } |
||
| 790 | if (!mail_hooks::access('managefolders')) |
||
| 791 | { |
||
| 792 | unset($tree_actions['add']); |
||
| 793 | unset($tree_actions['move']); |
||
| 794 | unset($tree_actions['delete']); |
||
| 795 | unset($tree_actions['foldermanagement']); |
||
| 796 | // manage folders should not affect the ability to subscribe or unsubscribe |
||
| 797 | // to existing folders, it should only affect add/rename/move/delete |
||
| 798 | } |
||
| 799 | return $tree_actions; |
||
| 800 | } |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Ajax callback to subscribe / unsubscribe a Mailbox of an account |
||
| 804 | * |
||
| 805 | * @param {int} $_acc_id profile Id of selected mailbox |
||
| 806 | * @param {string} $_folderName name of mailbox needs to be subcribe or unsubscribed |
||
| 807 | * @param {boolean} $_status set true for subscribe and false to unsubscribe |
||
| 808 | */ |
||
| 809 | public function ajax_foldersubscription($_acc_id,$_folderName, $_status) |
||
| 810 | { |
||
| 811 | //Change the Mail object to related profileId |
||
| 812 | $this->changeProfile($_acc_id); |
||
| 813 | try{ |
||
| 814 | $this->mail_bo->icServer->subscribeMailbox($_folderName, $_status); |
||
| 815 | $this->mail_bo->resetFolderObjectCache($_acc_id); |
||
| 816 | $this->ajax_reloadNode($_acc_id,!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']); |
||
| 817 | } catch (Horde_Imap_Client_Exception $ex) { |
||
| 818 | error_log(__METHOD__.__LINE__."()". lang('Folder %1 %2 failed because of %3!',$_folderName,$_status?'subscribed':'unsubscribed', $ex)); |
||
| 819 | Framework::message(lang('Folder %1 %2 failed!',$_folderName,$_status)); |
||
| 820 | } |
||
| 821 | } |
||
| 822 | |||
| 823 | /** |
||
| 824 | * Ajax callback to fetch folders for given profile |
||
| 825 | * |
||
| 826 | * We currently load all folders of a given profile, tree can also load parts of a tree. |
||
| 827 | * |
||
| 828 | * @param string $_nodeID if of node whose children are requested |
||
| 829 | * @param boolean $_subscribedOnly flag to tell whether to fetch all or only subscribed (default) |
||
| 830 | */ |
||
| 831 | public function ajax_foldertree($_nodeID = null,$_subscribedOnly=null) |
||
| 832 | { |
||
| 833 | $nodeID = $_GET['id']; |
||
| 834 | if (!is_null($_nodeID)) $nodeID = $_nodeID; |
||
| 835 | $subscribedOnly = (bool)(!is_null($_subscribedOnly)?$_subscribedOnly:!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']); |
||
| 836 | $fetchCounters = !is_null($_nodeID); |
||
| 837 | list($_profileID,$_folderName) = explode(self::$delimiter,$nodeID,2); |
||
| 838 | |||
| 839 | if (!empty($_folderName)) $fetchCounters = true; |
||
| 840 | |||
| 841 | // Check if it is called for refresh root |
||
| 842 | // then we need to reinitialized the index tree |
||
| 843 | if(!$nodeID && !$_profileID) |
||
| 844 | { |
||
| 845 | $data = $this->mail_tree->getInitialIndexTree(null,null,null,null,true,!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']); |
||
| 846 | } |
||
| 847 | else |
||
| 848 | { |
||
| 849 | $data = $this->mail_tree->getTree($nodeID,$_profileID,0, false,$subscribedOnly,!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']); |
||
| 850 | } |
||
| 851 | if (!is_null($_nodeID)) return $data; |
||
| 852 | Etemplate\Widget\Tree::send_quote_json($data); |
||
| 853 | } |
||
| 854 | |||
| 855 | /** |
||
| 856 | * findNode - helper function to return only a branch of the tree |
||
| 857 | * |
||
| 858 | * @param array $_out out array (to be searched) |
||
| 859 | * @param string $_nodeID node to search for |
||
| 860 | * @param boolean $childElements return node itself, or only its child items |
||
| 861 | * @return array structured subtree |
||
| 862 | */ |
||
| 863 | static function findNode($_out, $_nodeID, $childElements = false) |
||
| 864 | { |
||
| 865 | foreach($_out['item'] as $node) |
||
| 866 | { |
||
| 867 | if (strcmp($node['id'],$_nodeID)===0) |
||
| 868 | { |
||
| 869 | //error_log(__METHOD__.__LINE__.':'.$_nodeID.'->'.$node['id']); |
||
| 870 | return ($childElements?$node['item']:$node); |
||
| 871 | } |
||
| 872 | elseif (is_array($node['item']) && strncmp($node['id'],$_nodeID,strlen($node['id']))===0 && strlen($_nodeID)>strlen($node['id'])) |
||
| 873 | { |
||
| 874 | //error_log(__METHOD__.__LINE__.' descend into '.$node['id']); |
||
| 875 | return self::findNode($node,$_nodeID,$childElements); |
||
| 876 | } |
||
| 877 | } |
||
| 878 | } |
||
| 879 | |||
| 880 | /** |
||
| 881 | * Method to execute spam actions |
||
| 882 | * |
||
| 883 | * @param type $_action action id |
||
| 884 | * @param type $_params |
||
| 885 | */ |
||
| 886 | public function ajax_spamAction($_action, $_params) |
||
| 887 | { |
||
| 888 | $msg = array(); |
||
| 889 | $response = Api\Json\Response::get(); |
||
| 890 | |||
| 891 | $id_parts = self::splitRowID($_params['row_id']); |
||
| 892 | if ($id_parts['profileID'] && $id_parts['profileID'] != $this->mail_bo->profileID) |
||
| 893 | { |
||
| 894 | $this->changeProfile($id_parts['profileID']); |
||
| 895 | } |
||
| 896 | $delimiter = $this->mail_bo->getHierarchyDelimiter(); |
||
| 897 | // Ham folder |
||
| 898 | $ham = $this->mail_bo->profileID.self::$delimiter.$this->mail_bo->icServer->acc_folder_ham; |
||
| 899 | // Junk folder |
||
| 900 | $junk = $this->mail_bo->profileID.self::$delimiter.$this->mail_bo->getJunkFolder(); |
||
| 901 | // Inbox folder |
||
| 902 | $inbox = $this->mail_bo->profileID.self::$delimiter.'INBOX'; |
||
| 903 | // Current Mailbox |
||
| 904 | $mailbox = $id_parts['folder']; |
||
| 905 | |||
| 906 | if ($GLOBALS['egw_info']['apps']['stylite']) |
||
| 907 | { |
||
| 908 | $_params['mailbody'] = $this->get_load_email_data($_params['uid'], null, $mailbox); |
||
| 909 | $msg[] = stylite_mail_spamtitan::execAction($_action, $_params, array( |
||
| 910 | 'userpwd' => $this->mail_bo->icServer->acc_imap_password, |
||
| 911 | 'user' => $this->mail_bo->icServer->acc_imap_username, |
||
| 912 | 'api_url' => $this->mail_bo->icServer->acc_spam_api |
||
| 913 | )); |
||
| 914 | } |
||
| 915 | switch ($_action) |
||
| 916 | { |
||
| 917 | case 'spam': |
||
| 918 | $this->ajax_copyMessages($junk, array( |
||
| 919 | 'all' => false, |
||
| 920 | 'msg' => array($_params['row_id']) |
||
| 921 | ), 'move'); |
||
| 922 | break; |
||
| 923 | case 'ham': |
||
| 924 | if ($ham) |
||
| 925 | { |
||
| 926 | $this->ajax_copyMessages($ham, array( |
||
| 927 | 'all' => false, |
||
| 928 | 'msg' => array($_params['row_id']) |
||
| 929 | ), 'copy'); |
||
| 930 | } |
||
| 931 | // Move mails to Inbox if they are in Junk folder |
||
| 932 | if ($junk == $this->mail_bo->profileID.self::$delimiter.$mailbox) |
||
| 933 | { |
||
| 934 | $this->ajax_copyMessages($inbox, array( |
||
| 935 | 'all' => false, |
||
| 936 | 'msg' => array($_params['row_id']) |
||
| 937 | ), 'move'); |
||
| 938 | } |
||
| 939 | break; |
||
| 940 | } |
||
| 941 | $response->apply('egw.message',[implode('\n',$msg)]); |
||
| 942 | } |
||
| 943 | |||
| 944 | /** |
||
| 945 | * Build spam actions |
||
| 946 | * |
||
| 947 | * @return array actions |
||
| 948 | */ |
||
| 949 | public function getSpamActions () |
||
| 950 | { |
||
| 951 | $actions = array ( |
||
| 952 | 'spamfilter' => array ( |
||
| 953 | 'caption' => 'Spam', |
||
| 954 | 'icon' => 'dhtmlxtree/MailFolderJunk', |
||
| 955 | 'children' => array ( |
||
| 956 | 'spam' => array ( |
||
| 957 | 'caption' => 'Report as Spam', |
||
| 958 | 'icon' => 'dhtmlxtree/MailFolderJunk', |
||
| 959 | 'onExecute' => 'javaScript:app.mail.spam_actions', |
||
| 960 | 'hint' => 'Report this email content as Spam - spam solutions like spamTitan will learn', |
||
| 961 | 'allowOnMultiple' => false |
||
| 962 | ), |
||
| 963 | 'ham' => array ( |
||
| 964 | 'caption' => 'Report as Ham', |
||
| 965 | 'icon' => 'ham', |
||
| 966 | 'onExecute' => 'javaScript:app.mail.spam_actions', |
||
| 967 | 'hint' => 'Report this email content as Ham (not spam) - spam solutions like spamTitan will learn', |
||
| 968 | 'allowOnMultiple' => false |
||
| 969 | ) |
||
| 970 | ) |
||
| 971 | ) |
||
| 972 | ); |
||
| 973 | $account = Mail\Account::read($this->mail_bo->profileID); |
||
| 974 | // spamTitan actions |
||
| 975 | if ($GLOBALS['egw_info']['apps']['stylite'] && $account->acc_spam_api) |
||
| 976 | { |
||
| 977 | $actions['spamfilter']['children'] = array_merge($actions['spamfilter']['children'], stylite_mail_spamtitan::getActions()); |
||
| 978 | } |
||
| 979 | return $actions; |
||
| 980 | } |
||
| 981 | |||
| 982 | /** |
||
| 983 | * Get actions / context menu for index |
||
| 984 | * |
||
| 985 | * Changes here, require to log out, as $content[self::$nm_index] get stored in session! |
||
| 986 | * @return array see nextmatch_widget::egw_actions() |
||
| 987 | */ |
||
| 988 | private function get_actions() |
||
| 989 | { |
||
| 990 | static $accArray=array(); // buffer identity names on single request |
||
| 991 | // duplicated from mail_hooks |
||
| 992 | static $deleteOptions = array( |
||
| 993 | 'move_to_trash' => 'move to trash', |
||
| 994 | 'mark_as_deleted' => 'mark as deleted', |
||
| 995 | 'remove_immediately' => 'remove immediately', |
||
| 996 | ); |
||
| 997 | // todo: real hierarchical folder list |
||
| 998 | $lastFolderUsedForMove = null; |
||
| 999 | $moveactions = array(); |
||
| 1000 | $archiveFolder = $this->mail_bo->getArchiveFolder(); |
||
| 1001 | $lastFoldersUsedForMoveCont = Api\Cache::getCache(Api\Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*1); |
||
| 1002 | //error_log(__METHOD__.__LINE__." StoredFolders->".array2string($lastFoldersUsedForMoveCont)); |
||
| 1003 | //error_log(__METHOD__.__LINE__.' ProfileId:'.$this->mail_bo->profileID." StoredFolders->(".count($lastFoldersUsedForMoveCont[$this->mail_bo->profileID]).") ".array2string($lastFoldersUsedForMoveCont[$this->mail_bo->profileID])); |
||
| 1004 | if (is_null($accArray)) |
||
| 1005 | { |
||
| 1006 | foreach(Mail\Account::search($only_current_user=true, false) as $acc_id => $accountObj) |
||
| 1007 | { |
||
| 1008 | //error_log(__METHOD__.__LINE__.array2string($accountObj)); |
||
| 1009 | if (!$accountObj->is_imap()) |
||
| 1010 | { |
||
| 1011 | // not to be used for IMAP Foldertree, as there is no Imap host |
||
| 1012 | continue; |
||
| 1013 | } |
||
| 1014 | $identity_name = Mail\Account::identity_name($accountObj,true,$GLOBALS['egw_info']['user']['acount_id']); |
||
| 1015 | $accArray[$acc_id] = str_replace(array('<','>'),array('[',']'),$identity_name);// as angle brackets are quoted, display in Javascript messages when used is ugly, so use square brackets instead |
||
| 1016 | } |
||
| 1017 | } |
||
| 1018 | if (!is_array($lastFoldersUsedForMoveCont)) $lastFoldersUsedForMoveCont=array(); |
||
| 1019 | foreach (array_keys($lastFoldersUsedForMoveCont) as $pid) |
||
| 1020 | { |
||
| 1021 | if ($this->mail_bo->profileID==$pid && isset($lastFoldersUsedForMoveCont[$this->mail_bo->profileID])) |
||
| 1022 | { |
||
| 1023 | $_folder = $this->mail_bo->icServer->getCurrentMailbox(); |
||
| 1024 | //error_log(__METHOD__.__LINE__.' '.$_folder."<->".$lastFoldersUsedForMoveCont[$this->mail_bo->profileID].function_backtrace()); |
||
| 1025 | $counter =1; |
||
| 1026 | foreach ($lastFoldersUsedForMoveCont[$this->mail_bo->profileID] as $i => $lastFolderUsedForMoveCont) |
||
| 1027 | { |
||
| 1028 | $moveaction = 'move_'; |
||
| 1029 | if ($_folder!=$i) |
||
| 1030 | { |
||
| 1031 | $moveaction .= $lastFolderUsedForMoveCont; |
||
| 1032 | //error_log(__METHOD__.__LINE__.'#'.$moveaction); |
||
| 1033 | //error_log(__METHOD__.__LINE__.'#'.$currentArchiveActionKey); |
||
| 1034 | if ($this->mail_bo->folderExists($i)) // only 10 entries per mailaccount.Control this on setting the buffered folders |
||
| 1035 | { |
||
| 1036 | $fS['profileID'] = $this->mail_bo->profileID; |
||
| 1037 | $fS['profileName'] = $accArray[$this->mail_bo->profileID]; |
||
| 1038 | $fS['shortDisplayName'] = $i; |
||
| 1039 | $moveactions[$moveaction] = $fS; |
||
| 1040 | $counter ++; |
||
| 1041 | } |
||
| 1042 | else |
||
| 1043 | { |
||
| 1044 | unset($lastFoldersUsedForMoveCont[$this->mail_bo->profileID][$i]); |
||
| 1045 | } |
||
| 1046 | //error_log(array2string($moveactions[$moveaction])); |
||
| 1047 | } |
||
| 1048 | } |
||
| 1049 | } |
||
| 1050 | elseif ($this->mail_bo->profileID!=$pid && isset($lastFoldersUsedForMoveCont[$pid]) && !empty($lastFoldersUsedForMoveCont[$pid])) |
||
| 1051 | { |
||
| 1052 | $counter =1; |
||
| 1053 | foreach ($lastFoldersUsedForMoveCont[$pid] as $i => $lastFolderUsedForMoveCont) |
||
| 1054 | { |
||
| 1055 | //error_log(__METHOD__.__LINE__."$i => $lastFolderUsedForMoveCont"); |
||
| 1056 | if (!empty($lastFolderUsedForMoveCont)) // only 10 entries per mailaccount.Control this on setting the buffered folders |
||
| 1057 | { |
||
| 1058 | $moveaction = 'move_'.$lastFolderUsedForMoveCont; |
||
| 1059 | //error_log(__METHOD__.__LINE__.'#'.$moveaction); |
||
| 1060 | $fS = array(); |
||
| 1061 | $fS['profileID'] = $pid; |
||
| 1062 | $fS['profileName'] = $accArray[$pid]; |
||
| 1063 | $fS['shortDisplayName'] = $i; |
||
| 1064 | $moveactions[$moveaction] = $fS; |
||
| 1065 | $counter ++; |
||
| 1066 | } |
||
| 1067 | } |
||
| 1068 | } |
||
| 1069 | } |
||
| 1070 | Api\Cache::setCache(Api\Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']),$lastFoldersUsedForMoveCont, $expiration=60*60*1); |
||
| 1071 | $group = 0; |
||
| 1072 | $actions = array( |
||
| 1073 | 'open' => array( |
||
| 1074 | 'caption' => lang('Open'), |
||
| 1075 | 'icon' => 'view', |
||
| 1076 | 'group' => ++$group, |
||
| 1077 | 'onExecute' => Api\Header\UserAgent::mobile()?'javaScript:app.mail.mobileView':'javaScript:app.mail.mail_open', |
||
| 1078 | 'allowOnMultiple' => false, |
||
| 1079 | 'default' => true, |
||
| 1080 | 'mobileViewTemplate' => 'view?'.filemtime(Api\Etemplate\Widget\Template::rel2path('/mail/templates/mobile/view.xet')) |
||
| 1081 | ), |
||
| 1082 | 'reply' => array( |
||
| 1083 | 'caption' => 'Reply', |
||
| 1084 | 'icon' => 'mail_reply', |
||
| 1085 | 'group' => ++$group, |
||
| 1086 | 'onExecute' => 'javaScript:app.mail.mail_compose', |
||
| 1087 | 'allowOnMultiple' => false, |
||
| 1088 | 'toolbarDefault' => true |
||
| 1089 | ), |
||
| 1090 | 'reply_all' => array( |
||
| 1091 | 'caption' => 'Reply All', |
||
| 1092 | 'icon' => 'mail_replyall', |
||
| 1093 | 'group' => $group, |
||
| 1094 | 'onExecute' => 'javaScript:app.mail.mail_compose', |
||
| 1095 | 'allowOnMultiple' => false, |
||
| 1096 | ), |
||
| 1097 | 'forward' => array( |
||
| 1098 | 'caption' => 'Forward', |
||
| 1099 | 'icon' => 'mail_forward', |
||
| 1100 | 'group' => $group, |
||
| 1101 | 'children' => array( |
||
| 1102 | 'forwardinline' => array( |
||
| 1103 | 'caption' => 'Inline', |
||
| 1104 | 'icon' => 'mail_forward', |
||
| 1105 | 'group' => $group, |
||
| 1106 | 'hint' => 'forward inline', |
||
| 1107 | 'onExecute' => 'javaScript:app.mail.mail_compose', |
||
| 1108 | 'allowOnMultiple' => false, |
||
| 1109 | 'toolbarDefault' => true |
||
| 1110 | ), |
||
| 1111 | 'forwardasattach' => array( |
||
| 1112 | 'caption' => 'Attachment', |
||
| 1113 | 'hint' => 'forward as attachment', |
||
| 1114 | 'icon' => 'mail_forward_attach', |
||
| 1115 | 'group' => $group, |
||
| 1116 | 'onExecute' => 'javaScript:app.mail.mail_compose', |
||
| 1117 | ), |
||
| 1118 | ), |
||
| 1119 | 'hideOnMobile' => true |
||
| 1120 | ), |
||
| 1121 | 'composeasnew' => array( |
||
| 1122 | 'caption' => 'Compose', |
||
| 1123 | 'icon' => 'new', |
||
| 1124 | 'hint' => 'Compose as new', |
||
| 1125 | 'group' => $group, |
||
| 1126 | 'onExecute' => 'javaScript:app.mail.mail_compose', |
||
| 1127 | 'allowOnMultiple' => false, |
||
| 1128 | ) |
||
| 1129 | ); |
||
| 1130 | $macounter=0; |
||
| 1131 | if (!empty($moveactions)) |
||
| 1132 | { |
||
| 1133 | //error_log(__METHOD__.__LINE__.array2string($moveactions)); |
||
| 1134 | $children=array(); |
||
| 1135 | $pID=0; |
||
| 1136 | foreach ($moveactions as $moveaction => $lastFolderUsedForMove) |
||
| 1137 | { |
||
| 1138 | $group = ($pID != $lastFolderUsedForMove['profileID'] && $macounter>0? $group+1 : $group); |
||
| 1139 | //error_log(__METHOD__.__LINE__."#$pID != ".$lastFolderUsedForMove['profileID']."#".$macounter.'#'.$groupCounter.'#'); |
||
| 1140 | $children = array_merge($children, |
||
| 1141 | array( |
||
| 1142 | $moveaction => array( |
||
| 1143 | 'caption' => (!empty($lastFolderUsedForMove['profileName'])?$lastFolderUsedForMove['profileName']:'('.$lastFolderUsedForMove['profileID'].')').': '.(isset($lastFolderUsedForMove['shortDisplayName'])?$lastFolderUsedForMove['shortDisplayName']:''), |
||
| 1144 | 'icon' => 'move', |
||
| 1145 | 'group' => $group, |
||
| 1146 | 'onExecute' => 'javaScript:app.mail.mail_move2folder', |
||
| 1147 | 'allowOnMultiple' => true, |
||
| 1148 | ) |
||
| 1149 | ) |
||
| 1150 | ); |
||
| 1151 | $pID = $lastFolderUsedForMove['profileID']; |
||
| 1152 | $macounter++; |
||
| 1153 | } |
||
| 1154 | $actions['moveto'] = array( |
||
| 1155 | 'caption' => lang('Move selected to'), |
||
| 1156 | 'icon' => 'move', |
||
| 1157 | 'group' => $group, |
||
| 1158 | 'children' => $children, |
||
| 1159 | ); |
||
| 1160 | |||
| 1161 | } else { |
||
| 1162 | $group++; |
||
| 1163 | } |
||
| 1164 | $spam_actions = $this->getSpamActions(); |
||
| 1165 | $group++; |
||
| 1166 | foreach ($spam_actions as &$action) |
||
| 1167 | { |
||
| 1168 | $action['group'] = $group; |
||
| 1169 | } |
||
| 1170 | //error_log(__METHOD__.__LINE__.$archiveFolder); |
||
| 1171 | $actions['move2'.$this->mail_bo->profileID.self::$delimiter.$archiveFolder] = array( //toarchive |
||
| 1172 | 'caption' => 'Move to archive', |
||
| 1173 | 'hint' => 'move selected mails to archive', |
||
| 1174 | 'icon' => 'archive', |
||
| 1175 | 'group' => $group++, |
||
| 1176 | 'enabled' => 'javaScript:app.mail.archivefolder_enabled', |
||
| 1177 | //'hideOnDisabled' => true, // does not work as expected on message-list |
||
| 1178 | 'onExecute' => 'javaScript:app.mail.mail_move2folder', |
||
| 1179 | 'shortcut' => KeyManager::shortcut(KeyManager::V, true, true), |
||
| 1180 | 'allowOnMultiple' => true, |
||
| 1181 | 'toolbarDefault' => false |
||
| 1182 | ); |
||
| 1183 | |||
| 1184 | $actions += array( |
||
| 1185 | 'infolog' => array( |
||
| 1186 | 'caption' => 'InfoLog', |
||
| 1187 | 'hint' => 'Save as InfoLog', |
||
| 1188 | 'icon' => 'infolog/navbar', |
||
| 1189 | 'group' => ++$group, |
||
| 1190 | 'onExecute' => 'javaScript:app.mail.mail_integrate', |
||
| 1191 | 'popup' => Link::get_registry('infolog', 'add_popup'), |
||
| 1192 | 'allowOnMultiple' => false, |
||
| 1193 | 'toolbarDefault' => true |
||
| 1194 | ), |
||
| 1195 | 'tracker' => array( |
||
| 1196 | 'caption' => 'Tracker', |
||
| 1197 | 'hint' => 'Save as ticket', |
||
| 1198 | 'group' => $group, |
||
| 1199 | 'icon' => 'tracker/navbar', |
||
| 1200 | 'onExecute' => 'javaScript:app.mail.mail_integrate', |
||
| 1201 | 'popup' => Link::get_registry('tracker', 'add_popup'), |
||
| 1202 | 'mail_import' => Api\Hooks::single(array('location' => 'mail_import'),'tracker'), |
||
| 1203 | 'allowOnMultiple' => false, |
||
| 1204 | ), |
||
| 1205 | 'calendar' => array( |
||
| 1206 | 'caption' => 'Calendar', |
||
| 1207 | 'hint' => 'Save as Calendar', |
||
| 1208 | 'icon' => 'calendar/navbar', |
||
| 1209 | 'group' => $group, |
||
| 1210 | 'onExecute' => 'javaScript:app.mail.mail_integrate', |
||
| 1211 | 'popup' => Link::get_registry('calendar', 'add_popup'), |
||
| 1212 | 'allowOnMultiple' => false, |
||
| 1213 | 'toolbarDefault' => true |
||
| 1214 | ), |
||
| 1215 | 'print' => array( |
||
| 1216 | 'caption' => 'Print', |
||
| 1217 | 'group' => ++$group, |
||
| 1218 | 'onExecute' => 'javaScript:app.mail.mail_print', |
||
| 1219 | 'allowOnMultiple' => false, |
||
| 1220 | 'hideOnMobile' => true |
||
| 1221 | ), |
||
| 1222 | 'save' => array( |
||
| 1223 | 'caption' => 'Save', |
||
| 1224 | 'group' => $group, |
||
| 1225 | 'icon' => 'fileexport', |
||
| 1226 | 'children' => array( |
||
| 1227 | 'save2disk' => array( |
||
| 1228 | 'caption' => 'Save to disk', |
||
| 1229 | 'hint' => 'Save message to disk', |
||
| 1230 | 'group' => $group, |
||
| 1231 | 'icon' => 'fileexport', |
||
| 1232 | 'onExecute' => 'javaScript:app.mail.mail_save', |
||
| 1233 | 'allowOnMultiple' => true, |
||
| 1234 | 'hideOnMobile' => true |
||
| 1235 | ), |
||
| 1236 | 'save2filemanager' => array( |
||
| 1237 | 'caption' => 'Filemanager', |
||
| 1238 | 'hint' => 'Save to filemanager', |
||
| 1239 | 'group' => $group, |
||
| 1240 | 'icon' => 'filemanager/navbar', |
||
| 1241 | 'onExecute' => 'javaScript:app.mail.mail_save2fm', |
||
| 1242 | 'allowOnMultiple' => true, |
||
| 1243 | ), |
||
| 1244 | ), |
||
| 1245 | 'hideOnMobile' => true |
||
| 1246 | ), |
||
| 1247 | 'view' => array( |
||
| 1248 | 'caption' => 'View', |
||
| 1249 | 'group' => $group, |
||
| 1250 | 'icon' => 'kmmsgread', |
||
| 1251 | 'children' => array( |
||
| 1252 | 'header' => array( |
||
| 1253 | 'caption' => 'Header', |
||
| 1254 | 'hint' => 'View header lines', |
||
| 1255 | 'group' => $group, |
||
| 1256 | 'icon' => 'kmmsgread', |
||
| 1257 | 'onExecute' => 'javaScript:app.mail.mail_header', |
||
| 1258 | 'allowOnMultiple' => false, |
||
| 1259 | ), |
||
| 1260 | 'mailsource' => array( |
||
| 1261 | 'caption' => 'Source', |
||
| 1262 | 'hint' => 'View full Mail Source', |
||
| 1263 | 'group' => $group, |
||
| 1264 | 'icon' => 'source', |
||
| 1265 | 'onExecute' => 'javaScript:app.mail.mail_mailsource', |
||
| 1266 | 'allowOnMultiple' => false, |
||
| 1267 | ), |
||
| 1268 | 'openastext' => array( |
||
| 1269 | 'caption' => lang('Text mode'), |
||
| 1270 | 'hint' => 'Open in Text mode', |
||
| 1271 | 'group' => ++$group, |
||
| 1272 | 'icon' => 'textmode', |
||
| 1273 | 'onExecute' => 'javaScript:app.mail.mail_openAsText', |
||
| 1274 | 'allowOnMultiple' => false, |
||
| 1275 | ), |
||
| 1276 | 'openashtml' => array( |
||
| 1277 | 'caption' => lang('HTML mode'), |
||
| 1278 | 'hint' => 'Open in HTML mode', |
||
| 1279 | 'group' => $group, |
||
| 1280 | 'icon' => 'htmlmode', |
||
| 1281 | 'onExecute' => 'javaScript:app.mail.mail_openAsHtml', |
||
| 1282 | 'allowOnMultiple' => false, |
||
| 1283 | ), |
||
| 1284 | ), |
||
| 1285 | 'hideOnMobile' => true |
||
| 1286 | ), |
||
| 1287 | 'mark' => array( |
||
| 1288 | 'caption' => 'Set / Remove Flags', |
||
| 1289 | 'icon' => 'read_small', |
||
| 1290 | 'group' => ++$group, |
||
| 1291 | 'children' => array( |
||
| 1292 | // icons used from http://creativecommons.org/licenses/by-sa/3.0/ |
||
| 1293 | // Artist: Led24 |
||
| 1294 | // Iconset Homepage: http://led24.de/iconset |
||
| 1295 | // License: CC Attribution 3.0 |
||
| 1296 | 'setLabel' => array( |
||
| 1297 | 'caption' => 'Set / Remove Labels', |
||
| 1298 | 'icon' => 'tag_message', |
||
| 1299 | 'group' => ++$group, |
||
| 1300 | // note this one is NOT a real CAPABILITY reported by the server, but added by selectMailbox |
||
| 1301 | 'enabled' => $this->mail_bo->icServer->hasCapability('SUPPORTS_KEYWORDS'), |
||
| 1302 | 'hideOnDisabled' => true, |
||
| 1303 | 'children' => array( |
||
| 1304 | 'unlabel' => array( |
||
| 1305 | 'group' => ++$group, |
||
| 1306 | 'caption' => "<font color='#ff0000'>".lang('remove all')."</font>", |
||
| 1307 | 'icon' => 'mail_label', |
||
| 1308 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1309 | 'shortcut' => KeyManager::shortcut(KeyManager::_0, true, true), |
||
| 1310 | ), |
||
| 1311 | 'label1' => array( |
||
| 1312 | 'group' => ++$group, |
||
| 1313 | 'caption' => "<font color='#ff0000'>".lang('important')."</font>", |
||
| 1314 | 'icon' => 'mail_label1', |
||
| 1315 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1316 | 'shortcut' => KeyManager::shortcut(KeyManager::_1, true, true), |
||
| 1317 | ), |
||
| 1318 | 'label2' => array( |
||
| 1319 | 'group' => $group, |
||
| 1320 | 'caption' => "<font color='#ff8000'>".lang('job')."</font>", |
||
| 1321 | 'icon' => 'mail_label2', |
||
| 1322 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1323 | 'shortcut' => KeyManager::shortcut(KeyManager::_2, true, true), |
||
| 1324 | ), |
||
| 1325 | 'label3' => array( |
||
| 1326 | 'group' => $group, |
||
| 1327 | 'caption' => "<font color='#008000'>".lang('personal')."</font>", |
||
| 1328 | 'icon' => 'mail_label3', |
||
| 1329 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1330 | 'shortcut' => KeyManager::shortcut(KeyManager::_3, true, true), |
||
| 1331 | ), |
||
| 1332 | 'label4' => array( |
||
| 1333 | 'group' => $group, |
||
| 1334 | 'caption' => "<font color='#0000ff'>".lang('to do')."</font>", |
||
| 1335 | 'icon' => 'mail_label4', |
||
| 1336 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1337 | 'shortcut' => KeyManager::shortcut(KeyManager::_4, true, true), |
||
| 1338 | ), |
||
| 1339 | 'label5' => array( |
||
| 1340 | 'group' => $group, |
||
| 1341 | 'caption' => "<font color='#8000ff'>".lang('later')."</font>", |
||
| 1342 | 'icon' => 'mail_label5', |
||
| 1343 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1344 | 'shortcut' => KeyManager::shortcut(KeyManager::_5, true, true), |
||
| 1345 | ), |
||
| 1346 | ), |
||
| 1347 | ), |
||
| 1348 | // modified icons from http://creativecommons.org/licenses/by-sa/3.0/ |
||
| 1349 | 'flagged' => array( |
||
| 1350 | 'group' => ++$group, |
||
| 1351 | 'caption' => 'Flag / Unflag', |
||
| 1352 | 'icon' => 'unread_flagged_small', |
||
| 1353 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1354 | 'hint' => 'Flag or Unflag a mail', |
||
| 1355 | 'shortcut' => KeyManager::shortcut(KeyManager::F, true, true), |
||
| 1356 | 'toolbarDefault' => true |
||
| 1357 | ), |
||
| 1358 | 'read' => array( |
||
| 1359 | 'group' => $group, |
||
| 1360 | 'caption' => 'Read / Unread', |
||
| 1361 | 'icon' => 'read_small', |
||
| 1362 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1363 | 'shortcut' => KeyManager::shortcut(KeyManager::U, true, true), |
||
| 1364 | |||
| 1365 | ), |
||
| 1366 | 'readall' => array( |
||
| 1367 | 'group' => ++$group, |
||
| 1368 | 'caption' => "<font color='#ff0000'>".lang('mark all as read')."</font>", |
||
| 1369 | 'icon' => 'read_small', |
||
| 1370 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1371 | 'hint' => 'mark all messages in folder as read', |
||
| 1372 | 'toolbarDefault' => false |
||
| 1373 | ), |
||
| 1374 | 'undelete' => array( |
||
| 1375 | 'group' => $group, |
||
| 1376 | 'caption' => 'Undelete', |
||
| 1377 | 'icon' => 'revert', |
||
| 1378 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1379 | ), |
||
| 1380 | ), |
||
| 1381 | ), |
||
| 1382 | 'delete' => array( |
||
| 1383 | 'caption' => 'Delete', |
||
| 1384 | 'hint' => $deleteOptions[$this->mail_bo->mailPreferences['deleteOptions']], |
||
| 1385 | 'group' => ++$group, |
||
| 1386 | 'onExecute' => 'javaScript:app.mail.mail_delete', |
||
| 1387 | 'toolbarDefault' => true |
||
| 1388 | ), |
||
| 1389 | 'drag_mail' => array( |
||
| 1390 | 'dragType' => array('mail'), |
||
| 1391 | 'type' => 'drag', |
||
| 1392 | //'onExecute' => 'javaScript:app.mail.mail_dragStart', |
||
| 1393 | ) |
||
| 1394 | ); |
||
| 1395 | //error_log(__METHOD__.__LINE__.array2string(array_keys($actions))); |
||
| 1396 | // save as tracker, save as infolog, as this are actions that are either available for all, or not, we do that for all and not via css-class disabling |
||
| 1397 | View Code Duplication | if (!isset($GLOBALS['egw_info']['user']['apps']['infolog'])) |
|
| 1398 | { |
||
| 1399 | unset($actions['infolog']); |
||
| 1400 | } |
||
| 1401 | View Code Duplication | if (!isset($GLOBALS['egw_info']['user']['apps']['tracker'])) |
|
| 1402 | { |
||
| 1403 | unset($actions['tracker']); |
||
| 1404 | } |
||
| 1405 | View Code Duplication | if (!isset($GLOBALS['egw_info']['user']['apps']['calendar'])) |
|
| 1406 | { |
||
| 1407 | unset($actions['calendar']); |
||
| 1408 | } |
||
| 1409 | // remove vfs actions if the user has no run access to filemanager |
||
| 1410 | if (!$GLOBALS['egw_info']['user']['apps']['filemanager']) |
||
| 1411 | { |
||
| 1412 | unset($actions['save']['children']['save2filemanager']); |
||
| 1413 | } |
||
| 1414 | return array_merge($actions, $spam_actions); |
||
| 1415 | } |
||
| 1416 | |||
| 1417 | /** |
||
| 1418 | * Callback to fetch the rows for the nextmatch widget |
||
| 1419 | * |
||
| 1420 | * Function is static to not automatic call constructor in case profile is changed. |
||
| 1421 | * |
||
| 1422 | * @param array $query |
||
| 1423 | * @param array &$rows |
||
| 1424 | * @param array &$readonlys |
||
| 1425 | */ |
||
| 1426 | public static function get_rows(&$query,&$rows,&$readonlys) |
||
| 1427 | { |
||
| 1428 | unset($readonlys); // not used, but required by function signature |
||
| 1429 | |||
| 1430 | // handle possible profile change in get_rows |
||
| 1431 | if (!empty($query['selectedFolder'])) |
||
| 1432 | { |
||
| 1433 | list($_profileID,$folderName) = explode(self::$delimiter, $query['selectedFolder'], 2); |
||
| 1434 | if (is_numeric(($_profileID)) && $_profileID != $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']) |
||
| 1435 | { |
||
| 1436 | try { |
||
| 1437 | $mail_ui = new mail_ui(false); // do NOT run constructor, as we change profile anyway |
||
| 1438 | $mail_ui->changeProfile($_profileID); |
||
| 1439 | $query['actions'] = $mail_ui->get_actions(); |
||
| 1440 | } |
||
| 1441 | catch(Exception $e) |
||
| 1442 | { |
||
| 1443 | unset($e); |
||
| 1444 | $rows=array(); |
||
| 1445 | return 0; |
||
| 1446 | } |
||
| 1447 | if (empty($folderName)) $query['selectedFolder'] = $_profileID.self::$delimiter.'INBOX'; |
||
| 1448 | } |
||
| 1449 | } |
||
| 1450 | if (!isset($mail_ui)) |
||
| 1451 | { |
||
| 1452 | try |
||
| 1453 | { |
||
| 1454 | $mail_ui = new mail_ui(true); // run constructor for current profile |
||
| 1455 | } |
||
| 1456 | catch(Exception $e) |
||
| 1457 | { |
||
| 1458 | unset($e); |
||
| 1459 | $rows=array(); |
||
| 1460 | return 0; |
||
| 1461 | } |
||
| 1462 | if (empty($query['selectedFolder'])) $query['selectedFolder'] = $mail_ui->mail_bo->profileID.self::$delimiter.'INBOX'; |
||
| 1463 | } |
||
| 1464 | //error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Start:'.$query['start'].' NumRows:'.$query['num_rows'].array2string($query['order']).'->'.array2string($query['sort'])); |
||
| 1465 | //Mail::$debugTimes=true; |
||
| 1466 | if (Mail::$debugTimes) $starttime = microtime(true); |
||
| 1467 | //$query['search'] is the phrase in the searchbox |
||
| 1468 | |||
| 1469 | $mail_ui->mail_bo->restoreSessionData(); |
||
| 1470 | if (isset($query['selectedFolder'])) $mail_ui->mail_bo->sessionData['mailbox']=$query['selectedFolder']; |
||
| 1471 | |||
| 1472 | $sRToFetch = null; |
||
| 1473 | list($_profileID,$_folderName) = explode(self::$delimiter,$query['selectedFolder'],2); |
||
| 1474 | if (strpos($_folderName,self::$delimiter)!==false) |
||
| 1475 | { |
||
| 1476 | list($app,$_profileID,$_folderName) = explode(self::$delimiter,$_folderName,3); |
||
| 1477 | unset($app); |
||
| 1478 | } |
||
| 1479 | //save selected Folder to sessionData (mailbox)->currentFolder |
||
| 1480 | if (isset($query['selectedFolder'])) $mail_ui->mail_bo->sessionData['mailbox']=$_folderName; |
||
| 1481 | $toSchema = false;//decides to select list schema with column to selected (if false fromaddress is default) |
||
| 1482 | if ($mail_ui->mail_bo->folderExists($_folderName)) |
||
| 1483 | { |
||
| 1484 | $toSchema = $mail_ui->mail_bo->isDraftFolder($_folderName,false)||$mail_ui->mail_bo->isSentFolder($_folderName,false)||$mail_ui->mail_bo->isTemplateFolder($_folderName,false); |
||
| 1485 | } |
||
| 1486 | else |
||
| 1487 | { |
||
| 1488 | // take the extra time on failure |
||
| 1489 | if (!$mail_ui->mail_bo->folderExists($_folderName,true)) |
||
| 1490 | { |
||
| 1491 | //error_log(__METHOD__.__LINE__.' Test on Folder:'.$_folderName.' failed; Using INBOX instead'); |
||
| 1492 | $query['selectedFolder']=$mail_ui->mail_bo->sessionData['mailbox']=$_folderName='INBOX'; |
||
| 1493 | } |
||
| 1494 | } |
||
| 1495 | $rowsFetched['messages'] = null; |
||
| 1496 | $offset = $query['start']+1; // we always start with 1 |
||
| 1497 | $maxMessages = $query['num_rows']; |
||
| 1498 | //error_log(__METHOD__.__LINE__.array2string($query)); |
||
| 1499 | $sort = ($query['order']=='address'?($toSchema?'toaddress':'fromaddress'):$query['order']); |
||
| 1500 | if (!empty($query['search'])||($query['cat_id']=='bydate' && (!empty($query['startdate'])||!empty($query['enddate'])))) |
||
| 1501 | { |
||
| 1502 | if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID])) |
||
| 1503 | { |
||
| 1504 | Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10); |
||
| 1505 | if (!isset(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID])) |
||
| 1506 | { |
||
| 1507 | Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]=true; |
||
| 1508 | } |
||
| 1509 | } |
||
| 1510 | //error_log(__METHOD__.__LINE__.' Startdate:'.$query['startdate'].' Enddate'.$query['enddate']); |
||
| 1511 | $cutoffdate = $cutoffdate2 = null; |
||
| 1512 | if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'],'ts');//SINCE, enddate |
||
| 1513 | if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate |
||
| 1514 | //error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate); |
||
| 1515 | $filter = array( |
||
| 1516 | 'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')), |
||
| 1517 | 'type' => ($query['cat_id']?$query['cat_id']:(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?'quick':'subject')), |
||
| 1518 | 'string' => $query['search'], |
||
| 1519 | 'status' => 'any', |
||
| 1520 | //'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2) |
||
| 1521 | ); |
||
| 1522 | if ($query['enddate']||$query['startdate']) { |
||
| 1523 | $filter['range'] = "BETWEEN"; |
||
| 1524 | if ($cutoffdate) { |
||
| 1525 | $filter[(empty($cutoffdate2)?'date':'since')] = date("d-M-Y", $cutoffdate); |
||
| 1526 | if (empty($cutoffdate2)) $filter['range'] = "SINCE"; |
||
| 1527 | } |
||
| 1528 | if ($cutoffdate2) { |
||
| 1529 | $filter[(empty($cutoffdate)?'date':'before')] = date("d-M-Y", $cutoffdate2); |
||
| 1530 | if (empty($cutoffdate)) $filter['range'] = "BEFORE"; |
||
| 1531 | } |
||
| 1532 | } |
||
| 1533 | } |
||
| 1534 | else |
||
| 1535 | { |
||
| 1536 | $filter = array(); |
||
| 1537 | } |
||
| 1538 | if ($query['filter']) |
||
| 1539 | { |
||
| 1540 | $filter['status'] = $query['filter']; |
||
| 1541 | } |
||
| 1542 | $reverse = ($query['sort']=='ASC'?false:true); |
||
| 1543 | $prefchanged = false; |
||
| 1544 | View Code Duplication | if (!isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType']) || ($query['cat_id'] !=$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType'])) |
|
| 1545 | { |
||
| 1546 | //error_log(__METHOD__.__LINE__.' Changing userPref ActivesearchType:'.$query['cat_id']); |
||
| 1547 | $GLOBALS['egw']->preferences->add('mail','ActiveSearchType',$query['cat_id'],'user'); |
||
| 1548 | $prefchanged = true; |
||
| 1549 | } |
||
| 1550 | View Code Duplication | if (!isset($GLOBALS['egw_info']['user']['preferences']['mail']['ShowDetails']) || ($query['filter2'] !=$GLOBALS['egw_info']['user']['preferences']['mail']['ShowDetails'])) |
|
| 1551 | { |
||
| 1552 | $GLOBALS['egw']->preferences->add('mail','ShowDetails',$query['filter2'],'user'); |
||
| 1553 | $prefchanged = true; |
||
| 1554 | } |
||
| 1555 | if ($prefchanged) |
||
| 1556 | { |
||
| 1557 | // save prefs |
||
| 1558 | $GLOBALS['egw']->preferences->save_repository(true); |
||
| 1559 | } |
||
| 1560 | //error_log(__METHOD__.__LINE__.' maxMessages:'.$maxMessages.' Offset:'.$offset.' Filter:'.array2string($mail_ui->sessionData['messageFilter'])); |
||
| 1561 | /* |
||
| 1562 | $cutoffdate = Api\DateTime::to('now','ts')-(3600*24*6);//SINCE, enddate |
||
| 1563 | $cutoffdate2 = Api\DateTime::to('now','ts')-(3600*24*3);//BEFORE, startdate |
||
| 1564 | $filter['range'] = "BETWEEN";// we support SINCE, BEFORE, BETWEEN and ON |
||
| 1565 | $filter['since'] = date("d-M-Y", $cutoffdate); |
||
| 1566 | $filter['before']= date("d-M-Y", $cutoffdate2); |
||
| 1567 | */ |
||
| 1568 | try |
||
| 1569 | { |
||
| 1570 | if ($maxMessages > 75) |
||
| 1571 | { |
||
| 1572 | $rByUid = true; |
||
| 1573 | $_sR = $mail_ui->mail_bo->getSortedList( |
||
| 1574 | $_folderName, |
||
| 1575 | $sort, |
||
| 1576 | $reverse, |
||
| 1577 | $filter, |
||
| 1578 | $rByUid |
||
| 1579 | ); |
||
| 1580 | $rowsFetched['messages'] = $_sR['count']; |
||
| 1581 | $ids = $_sR['match']->ids; |
||
| 1582 | // if $sR is false, something failed fundamentally |
||
| 1583 | if($reverse === true) $ids = ($ids===false?array():array_reverse((array)$ids)); |
||
| 1584 | $sR = array_slice((array)$ids,($offset==0?0:$offset-1),$maxMessages); // we need only $maxMessages of uids |
||
| 1585 | $sRToFetch = $sR;//array_slice($sR,0,50); // we fetch only the headers of a subset of the fetched uids |
||
| 1586 | //error_log(__METHOD__.__LINE__.' Rows fetched (UID only):'.count($sR).' Data:'.array2string($sR)); |
||
| 1587 | $maxMessages = 75; |
||
| 1588 | $sortResultwH['header'] = array(); |
||
| 1589 | if (count($sRToFetch)>0) |
||
| 1590 | { |
||
| 1591 | //error_log(__METHOD__.__LINE__.' Headers to fetch with UIDs:'.count($sRToFetch).' Data:'.array2string($sRToFetch)); |
||
| 1592 | $sortResult = array(); |
||
| 1593 | // fetch headers |
||
| 1594 | $sortResultwH = $mail_ui->mail_bo->getHeaders( |
||
| 1595 | $_folderName, |
||
| 1596 | $offset, |
||
| 1597 | $maxMessages, |
||
| 1598 | $sort, |
||
| 1599 | $reverse, |
||
| 1600 | $filter, |
||
| 1601 | $sRToFetch, |
||
| 1602 | true, //cacheResult |
||
| 1603 | ($query['filter2']?true:false) // fetchPreview |
||
| 1604 | ); |
||
| 1605 | } |
||
| 1606 | } |
||
| 1607 | else |
||
| 1608 | { |
||
| 1609 | $sortResult = array(); |
||
| 1610 | // fetch headers |
||
| 1611 | $sortResultwH = $mail_ui->mail_bo->getHeaders( |
||
| 1612 | $_folderName, |
||
| 1613 | $offset, |
||
| 1614 | $maxMessages, |
||
| 1615 | $sort, |
||
| 1616 | $reverse, |
||
| 1617 | $filter, |
||
| 1618 | null, // this uids only |
||
| 1619 | true, // cacheResult |
||
| 1620 | ($query['filter2']?true:false) // fetchPreview |
||
| 1621 | ); |
||
| 1622 | $rowsFetched['messages'] = $sortResultwH['info']['total']; |
||
| 1623 | } |
||
| 1624 | } |
||
| 1625 | catch (Exception $e) |
||
| 1626 | { |
||
| 1627 | $sortResultwH=array(); |
||
| 1628 | $sR=array(); |
||
| 1629 | self::callWizard($e->getMessage(), false, 'error'); |
||
| 1630 | } |
||
| 1631 | $response = Api\Json\Response::get(); |
||
| 1632 | // unlock immediately after fetching the rows |
||
| 1633 | if (stripos($_GET['menuaction'],'ajax_get_rows')!==false) |
||
| 1634 | { |
||
| 1635 | //error_log(__METHOD__.__LINE__.' unlock tree ->'.$_GET['menuaction']); |
||
| 1636 | $response->call('app.mail.unlock_tree'); |
||
| 1637 | } |
||
| 1638 | |||
| 1639 | if (is_array($sR) && count($sR)>0) |
||
| 1640 | { |
||
| 1641 | foreach ((array)$sR as $key => $v) |
||
| 1642 | { |
||
| 1643 | if (array_key_exists($key,(array)$sortResultwH['header'])==true) |
||
| 1644 | { |
||
| 1645 | $sortResult['header'][] = $sortResultwH['header'][$key]; |
||
| 1646 | } |
||
| 1647 | else |
||
| 1648 | { |
||
| 1649 | if (!empty($v)) $sortResult['header'][] = array('uid'=>$v); |
||
| 1650 | } |
||
| 1651 | } |
||
| 1652 | } |
||
| 1653 | else |
||
| 1654 | { |
||
| 1655 | $sortResult = $sortResultwH; |
||
| 1656 | } |
||
| 1657 | $rowsFetched['rowsFetched'] = count($sortResult['header']); |
||
| 1658 | if (empty($rowsFetched['messages'])) $rowsFetched['messages'] = $rowsFetched['rowsFetched']; |
||
| 1659 | |||
| 1660 | //error_log(__METHOD__.__LINE__.' Rows fetched:'.$rowsFetched.' Data:'.array2string($sortResult)); |
||
| 1661 | $cols = array('row_id','uid','status','attachments','subject','address','toaddress','fromaddress','ccaddress','additionaltoaddress','date','size','modified','bodypreview'); |
||
| 1662 | if ($GLOBALS['egw_info']['user']['preferences']['common']['select_mode']=='EGW_SELECTMODE_TOGGLE') unset($cols[0]); |
||
| 1663 | $rows = $mail_ui->header2gridelements($sortResult['header'],$cols, $_folderName, $folderType=$toSchema); |
||
| 1664 | |||
| 1665 | // Save the session (since we are committing session) at the end |
||
| 1666 | // to make sure all necessary data are stored in session. |
||
| 1667 | // e.g.: Link:: get_data which is used to read attachments data. |
||
| 1668 | $mail_ui->mail_bo->saveSessionData(); |
||
| 1669 | |||
| 1670 | if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'Folder:'.$_folderName.' Start:'.$query['start'].' NumRows:'.$query['num_rows'],__METHOD__.__LINE__); |
||
| 1671 | return $rowsFetched['messages']; |
||
| 1672 | } |
||
| 1673 | |||
| 1674 | /** |
||
| 1675 | * function createRowID - create a unique rowID for the grid |
||
| 1676 | * |
||
| 1677 | * @param string $_folderName used to ensure the uniqueness of the uid over all folders |
||
| 1678 | * @param string $message_uid the message_Uid to be used for creating the rowID |
||
| 1679 | * @param boolean $_prependApp to indicate that the app 'mail' is to be used for creating the rowID |
||
| 1680 | * @return string - a colon separated string in the form [app:]accountID:profileID:folder:message_uid |
||
| 1681 | */ |
||
| 1682 | function createRowID($_folderName, $message_uid, $_prependApp=false) |
||
| 1683 | { |
||
| 1684 | return self::generateRowID($this->mail_bo->profileID, $_folderName, $message_uid, $_prependApp); |
||
| 1685 | } |
||
| 1686 | |||
| 1687 | /** |
||
| 1688 | * static function generateRowID - create a unique rowID for the grid |
||
| 1689 | * |
||
| 1690 | * @param integer $_profileID profile ID for the rowid to be used |
||
| 1691 | * @param string $_folderName to ensure the uniqueness of the uid over all folders |
||
| 1692 | * @param string $message_uid the message_Uid to be used for creating the rowID |
||
| 1693 | * @param boolean $_prependApp to indicate that the app 'mail' is to be used for creating the rowID |
||
| 1694 | * @return string - a colon separated string in the form [app:]accountID:profileID:folder:message_uid |
||
| 1695 | */ |
||
| 1696 | static function generateRowID($_profileID, $_folderName, $message_uid, $_prependApp=false) |
||
| 1697 | { |
||
| 1698 | return ($_prependApp?'mail'.self::$delimiter:'').trim($GLOBALS['egw_info']['user']['account_id']).self::$delimiter.$_profileID.self::$delimiter.base64_encode($_folderName).self::$delimiter.$message_uid; |
||
| 1699 | } |
||
| 1700 | |||
| 1701 | /** |
||
| 1702 | * function splitRowID - split the rowID into its parts |
||
| 1703 | * |
||
| 1704 | * @param string $_rowID string - a colon separated string in the form accountID:profileID:folder:message_uid |
||
| 1705 | * @return array populated named result array (accountID,profileID,folder,msgUID) |
||
| 1706 | */ |
||
| 1707 | static function splitRowID($_rowID) |
||
| 1708 | { |
||
| 1709 | $res = explode(self::$delimiter,$_rowID); |
||
| 1710 | // as a rowID is perceeded by app::, should be mail! |
||
| 1711 | //error_log(__METHOD__.__LINE__.array2string($res).' [0] isInt:'.is_int($res[0]).' [0] isNumeric:'.is_numeric($res[0]).' [0] isString:'.is_string($res[0]).' Count:'.count($res)); |
||
| 1712 | if (count($res)==4 && is_numeric($res[0]) ) |
||
| 1713 | { |
||
| 1714 | // we have an own created rowID; prepend app=mail |
||
| 1715 | array_unshift($res,'mail'); |
||
| 1716 | } |
||
| 1717 | return array('app'=>$res[0], 'accountID'=>$res[1], 'profileID'=>$res[2], 'folder'=>base64_decode($res[3]), 'msgUID'=>$res[4]); |
||
| 1718 | } |
||
| 1719 | |||
| 1720 | /** |
||
| 1721 | * Get actions for preview toolbar |
||
| 1722 | * |
||
| 1723 | * @return array |
||
| 1724 | */ |
||
| 1725 | function get_toolbar_actions() |
||
| 1726 | { |
||
| 1727 | $actions = $this->get_actions(); |
||
| 1728 | $arrActions = array('composeasnew', 'reply', 'reply_all', 'forward', 'flagged', 'delete', 'print', |
||
| 1729 | 'infolog', 'tracker', 'calendar', 'save', 'view', 'read', 'label1', 'label2', 'label3', 'label4', 'label5','spam', 'ham'); |
||
| 1730 | foreach( $arrActions as &$act) |
||
| 1731 | { |
||
| 1732 | //error_log(__METHOD__.__LINE__.' '.$act.'->'.array2string($actions[$act])); |
||
| 1733 | switch ($act) |
||
| 1734 | { |
||
| 1735 | case 'forward': |
||
| 1736 | $actionsenabled[$act]=$actions[$act]; |
||
| 1737 | break; |
||
| 1738 | case 'save': |
||
| 1739 | $actionsenabled[$act]=$actions[$act]; |
||
| 1740 | |||
| 1741 | break; |
||
| 1742 | case 'view': |
||
| 1743 | $actionsenabled[$act]=$actions[$act]; |
||
| 1744 | break; |
||
| 1745 | case 'flagged': |
||
| 1746 | $actionsenabled[$act]= $actions['mark']['children'][$act]; |
||
| 1747 | break; |
||
| 1748 | case 'read': |
||
| 1749 | $actionsenabled[$act]= $actions['mark']['children'][$act]; |
||
| 1750 | break; |
||
| 1751 | View Code Duplication | case 'label1': |
|
| 1752 | $actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('important'); |
||
| 1753 | $actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act]; |
||
| 1754 | break; |
||
| 1755 | View Code Duplication | case 'label2': |
|
| 1756 | $actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('job'); |
||
| 1757 | $actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act]; |
||
| 1758 | break; |
||
| 1759 | View Code Duplication | case 'label3': |
|
| 1760 | $actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('personal'); |
||
| 1761 | $actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act]; |
||
| 1762 | break; |
||
| 1763 | View Code Duplication | case 'label4': |
|
| 1764 | $actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('to do'); |
||
| 1765 | $actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act]; |
||
| 1766 | break; |
||
| 1767 | View Code Duplication | case 'label5': |
|
| 1768 | $actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('later'); |
||
| 1769 | $actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act]; |
||
| 1770 | break; |
||
| 1771 | case 'ham': |
||
| 1772 | case 'spam': |
||
| 1773 | $actionsenabled[$act]= $actions['spamfilter']['children'][$act]; |
||
| 1774 | break; |
||
| 1775 | default: |
||
| 1776 | if (isset($actions[$act])) $actionsenabled[$act]=$actions[$act]; |
||
| 1777 | } |
||
| 1778 | } |
||
| 1779 | unset($actionsenabled['drag_mail']); |
||
| 1780 | //error_log(array2string($actionsenabled['view'])); |
||
| 1781 | unset($actionsenabled['view']['children']['openastext']);//not supported in preview |
||
| 1782 | unset($actionsenabled['view']['children']['openashtml']);//not supported in preview |
||
| 1783 | |||
| 1784 | return $actionsenabled; |
||
| 1785 | } |
||
| 1786 | |||
| 1787 | /** |
||
| 1788 | * function header2gridelements - to populate the grid elements with the collected Data |
||
| 1789 | * |
||
| 1790 | * @param array $_headers headerdata to process |
||
| 1791 | * @param array $cols cols to populate |
||
| 1792 | * @param array $_folderName to ensure the uniqueness of the uid over all folders |
||
| 1793 | * @param array $_folderType used to determine if we need to populate from/to |
||
| 1794 | * @return array populated result array |
||
| 1795 | */ |
||
| 1796 | public function header2gridelements($_headers, $cols, $_folderName, $_folderType=0) |
||
| 1797 | { |
||
| 1798 | if (Mail::$debugTimes) $starttime = microtime(true); |
||
| 1799 | $rv = array(); |
||
| 1800 | $i=0; |
||
| 1801 | foreach((array)$_headers as $header) |
||
| 1802 | { |
||
| 1803 | $i++; |
||
| 1804 | $data = array(); |
||
| 1805 | //error_log(__METHOD__.array2string($header)); |
||
| 1806 | $message_uid = $header['uid']; |
||
| 1807 | $data['uid'] = $message_uid; |
||
| 1808 | $data['row_id']=$this->createRowID($_folderName,$message_uid); |
||
| 1809 | |||
| 1810 | $flags = ""; |
||
| 1811 | if(!empty($header['recent'])) $flags .= "R"; |
||
| 1812 | if(!empty($header['flagged'])) $flags .= "F"; |
||
| 1813 | if(!empty($header['answered'])) $flags .= "A"; |
||
| 1814 | if(!empty($header['forwarded'])) $flags .= "W"; |
||
| 1815 | if(!empty($header['deleted'])) $flags .= "D"; |
||
| 1816 | if(!empty($header['seen'])) $flags .= "S"; |
||
| 1817 | if(!empty($header['label1'])) $flags .= "1"; |
||
| 1818 | if(!empty($header['label2'])) $flags .= "2"; |
||
| 1819 | if(!empty($header['label3'])) $flags .= "3"; |
||
| 1820 | if(!empty($header['label4'])) $flags .= "4"; |
||
| 1821 | if(!empty($header['label5'])) $flags .= "5"; |
||
| 1822 | |||
| 1823 | $data["status"] = "<span class=\"status_img\"></span>"; |
||
| 1824 | //error_log(__METHOD__.array2string($header).' Flags:'.$flags); |
||
| 1825 | |||
| 1826 | // the css for this row |
||
| 1827 | $is_recent=false; |
||
| 1828 | $css_styles = array("mail"); |
||
| 1829 | if ($header['deleted']) { |
||
| 1830 | $css_styles[] = 'deleted'; |
||
| 1831 | } |
||
| 1832 | if ($header['recent'] && !($header['deleted'] || $header['seen'] || $header['answered'] || $header['forwarded'])) { |
||
| 1833 | $css_styles[] = 'recent'; |
||
| 1834 | $is_recent=true; |
||
| 1835 | } |
||
| 1836 | if ($header['priority'] < 3) { |
||
| 1837 | $css_styles[] = 'prio_high'; |
||
| 1838 | } |
||
| 1839 | if ($header['flagged']) { |
||
| 1840 | $css_styles[] = 'flagged'; |
||
| 1841 | } |
||
| 1842 | if (!$header['seen']) { |
||
| 1843 | $css_styles[] = 'unseen'; // different status image for recent // solved via css !important |
||
| 1844 | } |
||
| 1845 | if ($header['answered']) { |
||
| 1846 | $css_styles[] = 'replied'; |
||
| 1847 | } |
||
| 1848 | if ($header['forwarded']) { |
||
| 1849 | $css_styles[] = 'forwarded'; |
||
| 1850 | } |
||
| 1851 | if ($header['label1']) { |
||
| 1852 | $css_styles[] = 'labelone'; |
||
| 1853 | } |
||
| 1854 | if ($header['label2']) { |
||
| 1855 | $css_styles[] = 'labeltwo'; |
||
| 1856 | } |
||
| 1857 | if ($header['label3']) { |
||
| 1858 | $css_styles[] = 'labelthree'; |
||
| 1859 | } |
||
| 1860 | if ($header['label4']) { |
||
| 1861 | $css_styles[] = 'labelfour'; |
||
| 1862 | } |
||
| 1863 | if ($header['label5']) { |
||
| 1864 | $css_styles[] = 'labelfive'; |
||
| 1865 | } |
||
| 1866 | |||
| 1867 | //error_log(__METHOD__.array2string($css_styles)); |
||
| 1868 | |||
| 1869 | if (in_array("subject", $cols)) |
||
| 1870 | { |
||
| 1871 | // filter out undisplayable characters |
||
| 1872 | $search = array('[\016]','[\017]', |
||
| 1873 | '[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]', |
||
| 1874 | '[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]'); |
||
| 1875 | $replace = ''; |
||
| 1876 | |||
| 1877 | $header['subject'] = preg_replace($search,$replace,$header['subject']); |
||
| 1878 | // curly brackets get messed up by the template! |
||
| 1879 | |||
| 1880 | if (!empty($header['subject'])) { |
||
| 1881 | // make the subject shorter if it is to long |
||
| 1882 | $subject = $header['subject']; |
||
| 1883 | } else { |
||
| 1884 | $subject = '('. lang('no subject') .')'; |
||
| 1885 | } |
||
| 1886 | |||
| 1887 | $data["subject"] = $subject; // the mailsubject |
||
| 1888 | } |
||
| 1889 | |||
| 1890 | $imageHTMLBlock = ''; |
||
| 1891 | //error_log(__METHOD__.__LINE__.array2string($header)); |
||
| 1892 | if (in_array("attachments", $cols)) |
||
| 1893 | { |
||
| 1894 | if($header['mimetype'] == 'multipart/mixed' || |
||
| 1895 | $header['mimetype'] == 'multipart/signed' || |
||
| 1896 | $header['mimetype'] == 'multipart/related' || |
||
| 1897 | $header['mimetype'] == 'multipart/report' || |
||
| 1898 | $header['mimetype'] == 'text/calendar' || |
||
| 1899 | $header['mimetype'] == 'text/html' || |
||
| 1900 | substr($header['mimetype'],0,11) == 'application' || |
||
| 1901 | substr($header['mimetype'],0,5) == 'audio' || |
||
| 1902 | substr($header['mimetype'],0,5) == 'video' || |
||
| 1903 | $header['mimetype'] == 'multipart/alternative') |
||
| 1904 | { |
||
| 1905 | $image = Api\Html::image('mail','attach'); |
||
| 1906 | $imageHTMLBlock = ''; |
||
| 1907 | $datarowid = $this->createRowID($_folderName,$message_uid,true); |
||
| 1908 | $attachments = $header['attachments']; |
||
| 1909 | if (count($attachments)<1) |
||
| 1910 | { |
||
| 1911 | $image = ' '; |
||
| 1912 | } |
||
| 1913 | if (count($attachments)==1) |
||
| 1914 | { |
||
| 1915 | $imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'],$_folderName); |
||
| 1916 | $image = Api\Html::image('mail','attach',$attachments[0]['name'].(!empty($attachments[0]['mimeType'])?' ('.$attachments[0]['mimeType'].')':'')); |
||
| 1917 | } |
||
| 1918 | if (count($attachments)>1) |
||
| 1919 | { |
||
| 1920 | $imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'],$_folderName); |
||
| 1921 | $image = Api\Html::image('mail','attach',lang('%1 attachments',count($attachments))); |
||
| 1922 | } |
||
| 1923 | |||
| 1924 | $attachmentFlag = $image; |
||
| 1925 | } else { |
||
| 1926 | $attachmentFlag =' '; |
||
| 1927 | } |
||
| 1928 | // show priority flag |
||
| 1929 | if ($header['priority'] < 3) { |
||
| 1930 | $image = Api\Html::image('mail','prio_high'); |
||
| 1931 | } elseif ($header['priority'] > 3) { |
||
| 1932 | $image = Api\Html::image('mail','prio_low'); |
||
| 1933 | } else { |
||
| 1934 | $image = ''; |
||
| 1935 | } |
||
| 1936 | // show a flag for flagged messages |
||
| 1937 | $imageflagged =''; |
||
| 1938 | if ($header['flagged']) |
||
| 1939 | { |
||
| 1940 | $imageflagged = Api\Html::image('mail','unread_flagged_small'); |
||
| 1941 | } |
||
| 1942 | $data["attachments"] = $image.$attachmentFlag.$imageflagged; // icon for attachments available |
||
| 1943 | } |
||
| 1944 | |||
| 1945 | // sent or draft or template folder -> to address |
||
| 1946 | if (in_array("toaddress", $cols)) |
||
| 1947 | { |
||
| 1948 | // sent or drafts or template folder means foldertype > 0, use to address instead of from |
||
| 1949 | $data["toaddress"] = $header['to_address'];//Mail::htmlentities($header['to_address'],$this->charset); |
||
| 1950 | } |
||
| 1951 | |||
| 1952 | if (in_array("additionaltoaddress", $cols)) |
||
| 1953 | { |
||
| 1954 | $data['additionaltoaddress'] = $header['additional_to_addresses']; |
||
| 1955 | } |
||
| 1956 | //fromaddress |
||
| 1957 | if (in_array("fromaddress", $cols)) |
||
| 1958 | { |
||
| 1959 | $data["fromaddress"] = $header['sender_address']; |
||
| 1960 | } |
||
| 1961 | if (in_array("ccaddress", $cols)) |
||
| 1962 | { |
||
| 1963 | $data['ccaddress'] = $header['cc_addresses']; |
||
| 1964 | } |
||
| 1965 | if (in_array("date", $cols)) |
||
| 1966 | { |
||
| 1967 | $data["date"] = $header['date']; |
||
| 1968 | } |
||
| 1969 | if (in_array("modified", $cols)) |
||
| 1970 | { |
||
| 1971 | $data["modified"] = $header['internaldate']; |
||
| 1972 | } |
||
| 1973 | |||
| 1974 | if (in_array("size", $cols)) |
||
| 1975 | $data["size"] = $header['size']; /// size |
||
| 1976 | |||
| 1977 | $data["class"] = implode(' ', $css_styles); |
||
| 1978 | //translate style-classes back to flags |
||
| 1979 | $data['flags'] = Array(); |
||
| 1980 | if ($header['seen']) $data["flags"]['read'] = 'read'; |
||
| 1981 | foreach ($css_styles as &$flag) { |
||
| 1982 | if ($flag!='mail') |
||
| 1983 | { |
||
| 1984 | if ($flag=='labelone') {$data["flags"]['label1'] = 'label1';} |
||
| 1985 | elseif ($flag=='labeltwo') {$data["flags"]['label2'] = 'label2';} |
||
| 1986 | elseif ($flag=='labelthree') {$data["flags"]['label3'] = 'label3';} |
||
| 1987 | elseif ($flag=='labelfour') {$data["flags"]['label4'] = 'label4';} |
||
| 1988 | elseif ($flag=='labelfive') {$data["flags"]['label5'] = 'label5';} |
||
| 1989 | elseif ($flag=='unseen') {unset($data["flags"]['read']);} |
||
| 1990 | else $data["flags"][$flag] = $flag; |
||
| 1991 | } |
||
| 1992 | } |
||
| 1993 | if ($header['disposition-notification-to']) $data['dispositionnotificationto'] = $header['disposition-notification-to']; |
||
| 1994 | if (($header['mdnsent']||$header['mdnnotsent']|$header['seen'])&&isset($data['dispositionnotificationto'])) unset($data['dispositionnotificationto']); |
||
| 1995 | $data['attachmentsBlock'] = $imageHTMLBlock; |
||
| 1996 | $data['address'] = ($_folderType?$data["toaddress"]:$data["fromaddress"]); |
||
| 1997 | if (in_array("bodypreview", $cols)&&$header['bodypreview']) |
||
| 1998 | { |
||
| 1999 | $data["bodypreview"] = $header['bodypreview']; |
||
| 2000 | } |
||
| 2001 | $rv[] = $data; |
||
| 2002 | //error_log(__METHOD__.__LINE__.array2string($data)); |
||
| 2003 | } |
||
| 2004 | if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'Folder:'.$_folderName,__METHOD__.__LINE__); |
||
| 2005 | |||
| 2006 | // ToDo: call this ONLY if labels change |
||
| 2007 | Etemplate\Widget::setElementAttribute('toolbar', 'actions', $this->get_toolbar_actions()); |
||
| 2008 | |||
| 2009 | return $rv; |
||
| 2010 | } |
||
| 2011 | |||
| 2012 | /** |
||
| 2013 | * display messages header lines |
||
| 2014 | * |
||
| 2015 | * all params are passed as GET Parameters |
||
| 2016 | */ |
||
| 2017 | function displayHeader() |
||
| 2018 | { |
||
| 2019 | if(isset($_GET['id'])) $rowID = $_GET['id']; |
||
| 2020 | if(isset($_GET['part'])) $partID = $_GET['part']; |
||
| 2021 | |||
| 2022 | $hA = self::splitRowID($rowID); |
||
| 2023 | $uid = $hA['msgUID']; |
||
| 2024 | $mailbox = $hA['folder']; |
||
| 2025 | $icServerID = $hA['profileID']; |
||
| 2026 | $rememberServerID = $this->mail_bo->profileID; |
||
| 2027 | if ($icServerID && $icServerID != $this->mail_bo->profileID) |
||
| 2028 | { |
||
| 2029 | //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); |
||
| 2030 | $this->changeProfile($icServerID); |
||
| 2031 | } |
||
| 2032 | |||
| 2033 | $this->mail_bo->reopen($mailbox); |
||
| 2034 | $headers_in = $this->mail_bo->getMessageRawHeader($uid, $partID); |
||
| 2035 | |||
| 2036 | // add line breaks to $rawheaders |
||
| 2037 | $newRawHeaders = explode("\n",$headers_in); |
||
| 2038 | reset($newRawHeaders); |
||
| 2039 | |||
| 2040 | // reset $rawheaders |
||
| 2041 | $rawheaders = ""; |
||
| 2042 | // create it new, with good line breaks |
||
| 2043 | reset($newRawHeaders); |
||
| 2044 | while(list($key,$value) = @each($newRawHeaders)) { |
||
| 2045 | $rawheaders .= wordwrap($value, 90, "\n "); |
||
| 2046 | } |
||
| 2047 | |||
| 2048 | $this->mail_bo->closeConnection(); |
||
| 2049 | if ($rememberServerID != $this->mail_bo->profileID) |
||
| 2050 | { |
||
| 2051 | //error_log(__METHOD__.__LINE__.' change Profile back to where we came from->'.$rememberServerID); |
||
| 2052 | $this->changeProfile($rememberServerID); |
||
| 2053 | } |
||
| 2054 | |||
| 2055 | header('Content-type: text/html; charset=iso-8859-1'); |
||
| 2056 | print '<pre>'. htmlspecialchars($rawheaders, ENT_NOQUOTES, 'iso-8859-1') .'</pre>'; |
||
| 2057 | |||
| 2058 | } |
||
| 2059 | |||
| 2060 | /** |
||
| 2061 | * display messages |
||
| 2062 | * @param array $_requesteddata etemplate content |
||
| 2063 | * all params are passed as GET Parameters, but can be passed via ExecMethod2 as array too |
||
| 2064 | */ |
||
| 2065 | function displayMessage($_requesteddata = null) |
||
| 2066 | { |
||
| 2067 | if (is_null($_requesteddata)) $_requesteddata = $_GET; |
||
| 2068 | |||
| 2069 | $preventRedirect=false; |
||
| 2070 | if(isset($_requesteddata['id'])) $rowID = $_requesteddata['id']; |
||
| 2071 | if(isset($_requesteddata['part'])) $partID = $_requesteddata['part']!='null'?$_requesteddata['part']:null; |
||
| 2072 | if(isset($_requesteddata['mode'])) $preventRedirect = (($_requesteddata['mode']=='display' || $_requesteddata['mode'] == 'print')?true:false); |
||
| 2073 | |||
| 2074 | $hA = self::splitRowID($rowID); |
||
| 2075 | $uid = $hA['msgUID']; |
||
| 2076 | $mailbox = $hA['folder']; |
||
| 2077 | $icServerID = $hA['profileID']; |
||
| 2078 | $rememberServerID = $this->mail_bo->profileID; |
||
| 2079 | if ($icServerID && $icServerID != $this->mail_bo->profileID) |
||
| 2080 | { |
||
| 2081 | //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); |
||
| 2082 | $this->changeProfile($icServerID); |
||
| 2083 | } |
||
| 2084 | $htmlOptions = $this->mail_bo->htmlOptions; |
||
| 2085 | if (!empty($_requesteddata['tryastext'])) $htmlOptions = "only_if_no_text"; |
||
| 2086 | if (!empty($_requesteddata['tryashtml'])) $htmlOptions = "always_display"; |
||
| 2087 | |||
| 2088 | //error_log(__METHOD__.__LINE__.array2string($hA)); |
||
| 2089 | if (($this->mail_bo->isDraftFolder($mailbox)) && $_requesteddata['mode'] == 'print') |
||
| 2090 | { |
||
| 2091 | $response = Api\Json\Response::get(); |
||
| 2092 | $response->call('app.mail.print_for_compose', $rowID); |
||
| 2093 | } |
||
| 2094 | if (!$preventRedirect && ($this->mail_bo->isDraftFolder($mailbox) || $this->mail_bo->isTemplateFolder($mailbox))) |
||
| 2095 | { |
||
| 2096 | Egw::redirect_link('/index.php',array('menuaction'=>'mail.mail_compose.compose','id'=>$rowID,'from'=>'composefromdraft')); |
||
| 2097 | } |
||
| 2098 | $this->mail_bo->reopen($mailbox); |
||
| 2099 | // retrieve the flags of the message, before touching it. |
||
| 2100 | try |
||
| 2101 | { |
||
| 2102 | $headers = $this->mail_bo->getMessageHeader($uid, $partID,true,true,$mailbox); |
||
| 2103 | } |
||
| 2104 | catch (Api\Exception $e) |
||
| 2105 | { |
||
| 2106 | $error_msg[] = lang("ERROR: Message could not be displayed."); |
||
| 2107 | $error_msg[] = lang("In Mailbox: %1, with ID: %2, and PartID: %3",$mailbox,$uid,$partID); |
||
| 2108 | Framework::message($e->getMessage(), 'error'); |
||
| 2109 | } |
||
| 2110 | if (!empty($uid)) $this->mail_bo->getFlags($uid); |
||
| 2111 | $envelope = $this->mail_bo->getMessageEnvelope($uid, $partID,true,$mailbox); |
||
| 2112 | //error_log(__METHOD__.__LINE__.array2string($envelope)); |
||
| 2113 | $this->mail_bo->getMessageRawHeader($uid, $partID,$mailbox); |
||
| 2114 | $fetchEmbeddedImages = false; |
||
| 2115 | // if we are in HTML so its likely that we should show the embedded images; as a result |
||
| 2116 | // we do NOT want to see those, that are embedded in the list of attachments |
||
| 2117 | if ($htmlOptions !='always_display') $fetchEmbeddedImages = true; |
||
| 2118 | $attachments = $this->mail_bo->getMessageAttachments($uid, $partID, null, $fetchEmbeddedImages,true,true,$mailbox); |
||
| 2119 | //error_log(__METHOD__.__LINE__.array2string($attachments)); |
||
| 2120 | $attachmentHTMLBlock = self::createAttachmentBlock($attachments, $rowID, $uid, $mailbox); |
||
| 2121 | |||
| 2122 | $nonDisplayAbleCharacters = array('[\016]','[\017]', |
||
| 2123 | '[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]', |
||
| 2124 | '[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]'); |
||
| 2125 | |||
| 2126 | //error_log(__METHOD__.__LINE__.$mailBody); |
||
| 2127 | $this->mail_bo->closeConnection(); |
||
| 2128 | //$GLOBALS['egw_info']['flags']['currentapp'] = 'mail';//should not be needed |
||
| 2129 | $etpl = new Etemplate('mail.display'); |
||
| 2130 | $subject = $this->mail_bo->decode_subject(preg_replace($nonDisplayAbleCharacters,'',$envelope['SUBJECT']),false); |
||
| 2131 | |||
| 2132 | // Set up data for taglist widget(s) |
||
| 2133 | if ($envelope['FROM']==$envelope['SENDER']) unset($envelope['SENDER']); |
||
| 2134 | $sel_options = array(); |
||
| 2135 | foreach(array('SENDER','FROM','TO','CC','BCC') as $field) |
||
| 2136 | { |
||
| 2137 | if (!isset($envelope[$field])) continue; |
||
| 2138 | foreach($envelope[$field] as $field_data) |
||
| 2139 | { |
||
| 2140 | //error_log(__METHOD__.__LINE__.array2string($field_data)); |
||
| 2141 | $content[$field][] = $field_data; |
||
| 2142 | $sel_options[$field][] = array( |
||
| 2143 | // taglist requires these - not optional |
||
| 2144 | 'id' => $field_data, |
||
| 2145 | 'label' => str_replace('"',"'",$field_data), |
||
| 2146 | ); |
||
| 2147 | } |
||
| 2148 | } |
||
| 2149 | $actionsenabled = $this->getDisplayToolbarActions(); |
||
| 2150 | $content['displayToolbaractions'] = json_encode($actionsenabled); |
||
| 2151 | if (empty($subject)) $subject = lang('no subject'); |
||
| 2152 | $content['msg'] = (is_array($error_msg)?implode("<br>",$error_msg):$error_msg); |
||
| 2153 | // Send mail ID so we can use it for actions |
||
| 2154 | $content['mail_id'] = $rowID; |
||
| 2155 | if (!is_array($headers) || !isset($headers['DATE'])) |
||
| 2156 | { |
||
| 2157 | $headers['DATE'] = (is_array($envelope)&&$envelope['DATE']?$envelope['DATE']:''); |
||
| 2158 | } |
||
| 2159 | $content['mail_displaydate'] = Mail::_strtotime($headers['DATE'],'ts',true); |
||
| 2160 | $content['mail_displaysubject'] = $subject; |
||
| 2161 | $linkData = array('menuaction'=>"mail.mail_ui.loadEmailBody","_messageID"=>$rowID); |
||
| 2162 | if (!empty($partID)) $linkData['_partID']=$partID; |
||
| 2163 | if ($htmlOptions != $this->mail_bo->htmlOptions) $linkData['_htmloptions']=$htmlOptions; |
||
| 2164 | $content['mailDisplayBodySrc'] = Egw::link('/index.php',$linkData); |
||
| 2165 | $content['mail_displayattachments'] = $attachmentHTMLBlock; |
||
| 2166 | $content['mail_id']=$rowID; |
||
| 2167 | $content['mailDisplayContainerClass']=(count($attachments)?"mailDisplayContainer mailDisplayContainerFixedHeight":"mailDisplayContainer mailDisplayContainerFullHeight"); |
||
| 2168 | $content['mailDisplayAttachmentsClass']=(count($attachments)?"mailDisplayAttachments":"mail_DisplayNone"); |
||
| 2169 | |||
| 2170 | // DRAG attachments actions |
||
| 2171 | $etpl->setElementAttribute('mail_displayattachments', 'actions', array( |
||
| 2172 | 'file_drag' => array( |
||
| 2173 | 'dragType' => 'file', |
||
| 2174 | 'type' => 'drag', |
||
| 2175 | 'onExecute' => 'javaScript:app.mail.drag_attachment' |
||
| 2176 | ) |
||
| 2177 | )); |
||
| 2178 | $readonlys = $preserv = $content; |
||
| 2179 | if ($rememberServerID != $this->mail_bo->profileID) |
||
| 2180 | { |
||
| 2181 | //error_log(__METHOD__.__LINE__.' change Profile back to where we came from->'.$rememberServerID); |
||
| 2182 | $this->changeProfile($rememberServerID); |
||
| 2183 | } |
||
| 2184 | |||
| 2185 | $etpl->exec('mail.mail_ui.displayMessage',$content,$sel_options,$readonlys,$preserv,2); |
||
| 2186 | } |
||
| 2187 | |||
| 2188 | /** |
||
| 2189 | * Build actions for display toolbar |
||
| 2190 | */ |
||
| 2191 | function getDisplayToolbarActions () |
||
| 2192 | { |
||
| 2193 | $actions = $this->get_toolbar_actions(); |
||
| 2194 | $actions['mark']['children']['flagged']=array( |
||
| 2195 | 'group' => $actions['mark']['children']['flagged']['group'], |
||
| 2196 | 'caption' => 'Flagged', |
||
| 2197 | 'icon' => 'unread_flagged_small', |
||
| 2198 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 2199 | ); |
||
| 2200 | $actions['mark']['children']['unflagged']=array( |
||
| 2201 | 'group' => $actions['mark']['children']['flagged']['group'], |
||
| 2202 | 'caption' => 'Unflagged', |
||
| 2203 | 'icon' => 'read_flagged_small', |
||
| 2204 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 2205 | ); |
||
| 2206 | $actions['tracker']['toolbarDefault'] = true; |
||
| 2207 | $actions['forward']['toolbarDefault'] = true; |
||
| 2208 | |||
| 2209 | $compose = $actions['composeasnew']; |
||
| 2210 | unset($actions['composeasnew']); |
||
| 2211 | |||
| 2212 | $actions2 = array_reverse($actions,true); |
||
| 2213 | $actions2['composeasnew']= $compose; |
||
| 2214 | return array_reverse($actions2,true); |
||
| 2215 | } |
||
| 2216 | |||
| 2217 | /** |
||
| 2218 | * helper function to create the attachment block/table |
||
| 2219 | * |
||
| 2220 | * @param array $attachments array with the attachments information |
||
| 2221 | * @param string $rowID rowid of the message |
||
| 2222 | * @param int $uid uid of the message |
||
| 2223 | * @param string $mailbox mailbox identifier |
||
| 2224 | * @param boolean $_returnFullHTML flag wether to return HTML or data array |
||
| 2225 | * @return array|string data array or html or empty string |
||
| 2226 | */ |
||
| 2227 | static function createAttachmentBlock($attachments, $rowID, $uid, $mailbox,$_returnFullHTML=false) |
||
| 2228 | { |
||
| 2229 | $attachmentHTMLBlock=''; |
||
| 2230 | $attachmentHTML = array(); |
||
| 2231 | if (is_array($attachments) && count($attachments) > 0) { |
||
| 2232 | $url_img_vfs = Api\Html::image('filemanager','navbar', lang('Filemanager'), ' height="16"'); |
||
| 2233 | $url_img_vfs_save_all = Api\Html::image('mail','save_all', lang('Save all')); |
||
| 2234 | |||
| 2235 | foreach ($attachments as $key => $value) |
||
| 2236 | { |
||
| 2237 | $attachmentHTML[$key]['filename']= ($value['name'] ? ( $value['filename'] ? $value['filename'] : $value['name'] ) : lang('(no subject)')); |
||
| 2238 | $attachmentHTML[$key]['filename'] = Api\Translation::convert_jsonsafe($attachmentHTML[$key]['filename'],'utf-8'); |
||
| 2239 | //error_log(array2string($value)); |
||
| 2240 | //error_log(strtoupper($value['mimeType']) .'<->'. Api\MimeMagic::filename2mime($attachmentHTML[$key]['filename'])); |
||
| 2241 | if (strtoupper($value['mimeType']=='APPLICATION/OCTET-STREAM')) $value['mimeType'] = Api\MimeMagic::filename2mime($attachmentHTML[$key]['filename']); |
||
| 2242 | $attachmentHTML[$key]['type']=$value['mimeType']; |
||
| 2243 | $attachmentHTML[$key]['mimetype'] = Api\MimeMagic::mime2label($value['mimeType']); |
||
| 2244 | $hA = self::splitRowID($rowID); |
||
| 2245 | $uid = $hA['msgUID']; |
||
| 2246 | $mailbox = $hA['folder']; |
||
| 2247 | $acc_id = $hA['profileID']; |
||
| 2248 | |||
| 2249 | $attachmentHTML[$key]['mime_data'] = Link::set_data($value['mimeType'], 'EGroupware\\Api\\Mail::getAttachmentAccount', array( |
||
| 2250 | $acc_id, $mailbox, $uid, $value['partID'], $value['is_winmail'], true |
||
| 2251 | )); |
||
| 2252 | $attachmentHTML[$key]['size']=Vfs::hsize($value['size']); |
||
| 2253 | $attachmentHTML[$key]['attachment_number']=$key; |
||
| 2254 | $attachmentHTML[$key]['partID']=$value['partID']; |
||
| 2255 | $attachmentHTML[$key]['mail_id'] = $rowID; |
||
| 2256 | $attachmentHTML[$key]['winmailFlag']=$value['is_winmail']; |
||
| 2257 | $attachmentHTML[$key]['classSaveAllPossiblyDisabled'] = "mail_DisplayNone"; |
||
| 2258 | // reset mode array as it should be considered differently for |
||
| 2259 | // each attachment |
||
| 2260 | $mode = array(); |
||
| 2261 | switch(strtoupper($value['mimeType'])) |
||
| 2262 | { |
||
| 2263 | case 'MESSAGE/RFC822': |
||
| 2264 | $linkData = array |
||
| 2265 | ( |
||
| 2266 | 'menuaction' => 'mail.mail_ui.displayMessage', |
||
| 2267 | 'mode' => 'display', //message/rfc822 attachments should be opened in display mode |
||
| 2268 | 'id' => $rowID, |
||
| 2269 | 'part' => $value['partID'], |
||
| 2270 | 'is_winmail' => $value['is_winmail'] |
||
| 2271 | ); |
||
| 2272 | $windowName = 'displayMessage_'. $rowID.'_'.$value['partID']; |
||
| 2273 | $linkView = "egw_openWindowCentered('".Egw::link('/index.php',$linkData)."','$windowName',700,egw_getWindowOuterHeight());"; |
||
| 2274 | break; |
||
| 2275 | case 'IMAGE/JPEG': |
||
| 2276 | case 'IMAGE/PNG': |
||
| 2277 | case 'IMAGE/GIF': |
||
| 2278 | case 'IMAGE/BMP': |
||
| 2279 | // set mode for media mimetypes because we need |
||
| 2280 | // to structure a download url to be used maybe in expose. |
||
| 2281 | $mode = array( |
||
| 2282 | 'mode' => 'save' |
||
| 2283 | ); |
||
| 2284 | case 'APPLICATION/PDF': |
||
| 2285 | case 'TEXT/PLAIN': |
||
| 2286 | case 'TEXT/HTML': |
||
| 2287 | case 'TEXT/DIRECTORY': |
||
| 2288 | $sfxMimeType = $value['mimeType']; |
||
| 2289 | $buff = explode('.',$value['name']); |
||
| 2290 | $suffix = ''; |
||
| 2291 | if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime |
||
| 2292 | if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix); |
||
| 2293 | if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD') |
||
| 2294 | { |
||
| 2295 | $attachments[$key]['mimeType'] = $sfxMimeType; |
||
| 2296 | $value['mimeType'] = strtoupper($sfxMimeType); |
||
| 2297 | } |
||
| 2298 | case 'TEXT/X-VCARD': |
||
| 2299 | case 'TEXT/VCARD': |
||
| 2300 | case 'TEXT/CALENDAR': |
||
| 2301 | case 'TEXT/X-VCALENDAR': |
||
| 2302 | $linkData = array_merge(array |
||
| 2303 | ( |
||
| 2304 | 'menuaction' => 'mail.mail_ui.getAttachment', |
||
| 2305 | 'id' => $rowID, |
||
| 2306 | 'part' => $value['partID'], |
||
| 2307 | 'is_winmail' => $value['is_winmail'], |
||
| 2308 | 'mailbox' => base64_encode($mailbox), |
||
| 2309 | ) , $mode); |
||
| 2310 | $windowName = 'displayAttachment_'. $uid; |
||
| 2311 | $reg = '800x600'; |
||
| 2312 | // handle calendar/vcard |
||
| 2313 | if (strtoupper($value['mimeType'])=='TEXT/CALENDAR') |
||
| 2314 | { |
||
| 2315 | $windowName = 'displayEvent_'. $rowID; |
||
| 2316 | $reg2 = Link::get_registry('calendar','view_popup'); |
||
| 2317 | $attachmentHTML[$key]['popup']=(!empty($reg2) ? $reg2 : $reg); |
||
| 2318 | } |
||
| 2319 | if (strtoupper($value['mimeType'])=='TEXT/X-VCARD' || strtoupper($value['mimeType'])=='TEXT/VCARD') |
||
| 2320 | { |
||
| 2321 | $windowName = 'displayContact_'. $rowID; |
||
| 2322 | $reg2 = Link::get_registry('addressbook','add_popup'); |
||
| 2323 | $attachmentHTML[$key]['popup']=(!empty($reg2) ? $reg2 : $reg); |
||
| 2324 | } |
||
| 2325 | // apply to action |
||
| 2326 | list($width,$height) = explode('x',(!empty($reg2) ? $reg2 : $reg)); |
||
| 2327 | $linkView = "egw_openWindowCentered('".Egw::link('/index.php',$linkData)."','$windowName',$width,$height);"; |
||
| 2328 | break; |
||
| 2329 | default: |
||
| 2330 | $linkData = array |
||
| 2331 | ( |
||
| 2332 | 'menuaction' => 'mail.mail_ui.getAttachment', |
||
| 2333 | 'id' => $rowID, |
||
| 2334 | 'part' => $value['partID'], |
||
| 2335 | 'is_winmail' => $value['is_winmail'], |
||
| 2336 | 'mailbox' => base64_encode($mailbox), |
||
| 2337 | ); |
||
| 2338 | $linkView = "window.location.href = '".Egw::link('/index.php',$linkData)."';"; |
||
| 2339 | break; |
||
| 2340 | } |
||
| 2341 | // we either use mime_data for server-side supported mime-types or mime_url for client-side or download |
||
| 2342 | if (empty($attachmentHTML[$key]['mime_data'])) |
||
| 2343 | { |
||
| 2344 | $attachmentHTML[$key]['mime_url'] = Egw::link('/index.php',$linkData); |
||
| 2345 | unset($attachmentHTML[$key]['mime_data']); |
||
| 2346 | } |
||
| 2347 | $attachmentHTML[$key]['windowName'] = $windowName; |
||
| 2348 | |||
| 2349 | //error_log(__METHOD__.__LINE__.$linkView); |
||
| 2350 | $attachmentHTML[$key]['link_view'] = '<a href="#" ." title="'.$attachmentHTML[$key]['filename'].'" onclick="'.$linkView.' return false;"><b>'. |
||
| 2351 | ($value['name'] ? $value['name'] : lang('(no subject)')). |
||
| 2352 | '</b></a>'; |
||
| 2353 | |||
| 2354 | $linkData = array |
||
| 2355 | ( |
||
| 2356 | 'menuaction' => 'mail.mail_ui.getAttachment', |
||
| 2357 | 'mode' => 'save', |
||
| 2358 | 'id' => $rowID, |
||
| 2359 | 'part' => $value['partID'], |
||
| 2360 | 'is_winmail' => $value['is_winmail'], |
||
| 2361 | 'mailbox' => base64_encode($mailbox), |
||
| 2362 | ); |
||
| 2363 | $attachmentHTML[$key]['link_save'] ="<a href='".Egw::link('/index.php',$linkData)."' title='".$attachmentHTML[$key]['filename']."'>".Api\Html::image('mail','fileexport')."</a>"; |
||
| 2364 | |||
| 2365 | if ($GLOBALS['egw_info']['user']['apps']['filemanager']) |
||
| 2366 | { |
||
| 2367 | $link_vfs_save = Egw::link('/index.php',array( |
||
| 2368 | 'menuaction' => 'filemanager.filemanager_select.select', |
||
| 2369 | 'mode' => 'saveas', |
||
| 2370 | 'name' => $value['name'], |
||
| 2371 | 'mime' => strtolower($value['mimeType']), |
||
| 2372 | 'method' => 'mail.mail_ui.vfsSaveAttachment', |
||
| 2373 | 'id' => $rowID.'::'.$value['partID'].'::'.$value['is_winmail'], |
||
| 2374 | 'label' => lang('Save'), |
||
| 2375 | )); |
||
| 2376 | $vfs_save = "<a href='#' onclick=\"egw_openWindowCentered('$link_vfs_save','vfs_save_attachment','640','570',window.outerWidth/2,window.outerHeight/2); return false;\">$url_img_vfs</a>"; |
||
| 2377 | // add save-all icon for first attachment |
||
| 2378 | if (!$key && count($attachments) > 1) |
||
| 2379 | { |
||
| 2380 | $attachmentHTML[$key]['classSaveAllPossiblyDisabled'] = ""; |
||
| 2381 | foreach ($attachments as $ikey => $value) |
||
| 2382 | { |
||
| 2383 | //$rowID |
||
| 2384 | $ids["id[$ikey]"] = $rowID.'::'.$value['partID'].'::'.$value['is_winmail'].'::'.$value['name']; |
||
| 2385 | } |
||
| 2386 | $link_vfs_save = Egw::link('/index.php',array( |
||
| 2387 | 'menuaction' => 'filemanager.filemanager_select.select', |
||
| 2388 | 'mode' => 'select-dir', |
||
| 2389 | 'method' => 'mail.mail_ui.vfsSaveAttachment', |
||
| 2390 | 'label' => lang('Save all'), |
||
| 2391 | )+$ids); |
||
| 2392 | $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>"; |
||
| 2393 | } |
||
| 2394 | $attachmentHTML[$key]['link_save'] .= $vfs_save; |
||
| 2395 | //error_log(__METHOD__.__LINE__.$attachmentHTML[$key]['link_save']); |
||
| 2396 | } |
||
| 2397 | } |
||
| 2398 | $attachmentHTMLBlock="<table width='100%'>"; |
||
| 2399 | foreach ((array)$attachmentHTML as $row) |
||
| 2400 | { |
||
| 2401 | $attachmentHTMLBlock .= "<tr><td><div class='useEllipsis'>".$row['link_view'].'</div></td>'; |
||
| 2402 | $attachmentHTMLBlock .= "<td>".$row['mimetype'].'</td>'; |
||
| 2403 | $attachmentHTMLBlock .= "<td>".$row['size'].'</td>'; |
||
| 2404 | $attachmentHTMLBlock .= "<td>".$row['link_save'].'</td></tr>'; |
||
| 2405 | } |
||
| 2406 | $attachmentHTMLBlock .= "</table>"; |
||
| 2407 | } |
||
| 2408 | if (!$_returnFullHTML) |
||
| 2409 | { |
||
| 2410 | foreach ((array)$attachmentHTML as $ikey => $value) |
||
| 2411 | { |
||
| 2412 | unset($attachmentHTML[$ikey]['link_view']); |
||
| 2413 | unset($attachmentHTML[$ikey]['link_save']); |
||
| 2414 | } |
||
| 2415 | } |
||
| 2416 | return ($_returnFullHTML?$attachmentHTMLBlock:$attachmentHTML); |
||
| 2417 | } |
||
| 2418 | |||
| 2419 | /** |
||
| 2420 | * fetch vacation info from active Server using icServer object |
||
| 2421 | * |
||
| 2422 | * @param array $cachedVacations an array of cached vacations for an user |
||
| 2423 | * @return array|boolean array with vacation on success or false on failure |
||
| 2424 | */ |
||
| 2425 | function gatherVacation($cachedVacations = array()) |
||
| 2426 | { |
||
| 2427 | $isVacationEnabled = $this->mail_bo->icServer->acc_sieve_enabled && ($this->mail_bo->icServer->acc_sieve_host||$this->mail_bo->icServer->acc_imap_host); |
||
| 2428 | //error_log(__METHOD__.__LINE__.' Server:'.self::$icServerID.' Sieve Enabled:'.array2string($vacation)); |
||
| 2429 | |||
| 2430 | if ($isVacationEnabled) |
||
| 2431 | { |
||
| 2432 | $sieveServer = $this->mail_bo->icServer; |
||
| 2433 | try |
||
| 2434 | { |
||
| 2435 | $sieveServer->retrieveRules(); |
||
| 2436 | $vacation = $sieveServer->getVacation(); |
||
| 2437 | |||
| 2438 | $cachedVacations = array($sieveServer->acc_id => $vacation) + (array)$cachedVacations; |
||
| 2439 | // Set vacation to the instance cache for particular account with expiration of one day |
||
| 2440 | Api\Cache::setCache(Api\Cache::INSTANCE, 'email', 'vacationNotice'.$GLOBALS['egw_info']['user']['account_lid'], $cachedVacations, 60*60*24); |
||
| 2441 | } |
||
| 2442 | catch (PEAR_Exception $ex) |
||
| 2443 | { |
||
| 2444 | $this->callWizard($ex->getMessage(), true, 'error'); |
||
| 2445 | } |
||
| 2446 | } |
||
| 2447 | //error_log(__METHOD__.__LINE__.' Server:'.self::$icServerID.' Vacation retrieved:'.array2string($vacation)); |
||
| 2448 | return $vacation; |
||
| 2449 | } |
||
| 2450 | |||
| 2451 | /** |
||
| 2452 | * gather Info on how to display the quota info |
||
| 2453 | * |
||
| 2454 | * @param int $_usage amount of usage in Kb |
||
| 2455 | * @param int $_limit amount of limit in Kb |
||
| 2456 | * @return array returns an array of info used for quota |
||
| 2457 | * array( |
||
| 2458 | * class => string, |
||
| 2459 | * text => string, |
||
| 2460 | * percent => string, |
||
| 2461 | * freespace => integer |
||
| 2462 | * ) |
||
| 2463 | */ |
||
| 2464 | function quotaDisplay($_usage, $_limit) |
||
| 2465 | { |
||
| 2466 | $percent = $_limit == 0 ? 100 : round(($_usage*100)/$_limit); |
||
| 2467 | $limit = Mail::show_readable_size($_limit*1024); |
||
| 2468 | $usage = Mail::show_readable_size($_usage*1024); |
||
| 2469 | |||
| 2470 | if ($_limit > 0) |
||
| 2471 | { |
||
| 2472 | $text = $usage .'/'.$limit; |
||
| 2473 | switch ($percent) |
||
| 2474 | { |
||
| 2475 | case 90: |
||
| 2476 | $class ='mail-index_QuotaRed'; |
||
| 2477 | break; |
||
| 2478 | case 80: |
||
| 2479 | $class ='mail-index_QuotaYellow'; |
||
| 2480 | break; |
||
| 2481 | default: |
||
| 2482 | $class ='mail-index_QuotaGreen'; |
||
| 2483 | } |
||
| 2484 | } |
||
| 2485 | else |
||
| 2486 | { |
||
| 2487 | $text = $usage; |
||
| 2488 | $class ='mail-index_QuotaGreen'; |
||
| 2489 | } |
||
| 2490 | return array ( |
||
| 2491 | 'class' => $class, |
||
| 2492 | 'text' => lang('Quota: %1',$text), |
||
| 2493 | 'percent' => $percent, |
||
| 2494 | 'freespace' => $_limit*1024 - $_usage*1024 |
||
| 2495 | ); |
||
| 2496 | } |
||
| 2497 | |||
| 2498 | /** |
||
| 2499 | * display image |
||
| 2500 | * |
||
| 2501 | * all params are passed as GET Parameters |
||
| 2502 | */ |
||
| 2503 | function displayImage() |
||
| 2504 | { |
||
| 2505 | $uid = $_GET['uid']; |
||
| 2506 | $cid = base64_decode($_GET['cid']); |
||
| 2507 | $partID = urldecode($_GET['partID']); |
||
| 2508 | if (!empty($_GET['mailbox'])) $mailbox = base64_decode($_GET['mailbox']); |
||
| 2509 | |||
| 2510 | //error_log(__METHOD__.__LINE__.":$uid, $cid, $partID"); |
||
| 2511 | $this->mail_bo->reopen($mailbox); |
||
| 2512 | |||
| 2513 | $attachment = $this->mail_bo->getAttachmentByCID($uid, $cid, $partID, true); // true get contents as stream |
||
| 2514 | |||
| 2515 | $this->mail_bo->closeConnection(); |
||
| 2516 | |||
| 2517 | $GLOBALS['egw']->session->commit_session(); |
||
| 2518 | |||
| 2519 | if ($attachment) |
||
| 2520 | { |
||
| 2521 | header("Content-Type: ". $attachment->getType()); |
||
| 2522 | header('Content-Disposition: inline; filename="'. $attachment->getDispositionParameter('filename') .'"'); |
||
| 2523 | //header("Expires: 0"); |
||
| 2524 | // the next headers are for IE and SSL |
||
| 2525 | //header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
||
| 2526 | //header("Pragma: public"); |
||
| 2527 | Api\Session::cache_control(true); |
||
| 2528 | echo $attachment->getContents(); |
||
| 2529 | } |
||
| 2530 | else |
||
| 2531 | { |
||
| 2532 | // send a 404 Not found |
||
| 2533 | header("HTTP/1.1 404 Not found"); |
||
| 2534 | } |
||
| 2535 | exit(); |
||
| 2536 | } |
||
| 2537 | |||
| 2538 | function getAttachment() |
||
| 2539 | { |
||
| 2540 | if(isset($_GET['id'])) $rowID = $_GET['id']; |
||
| 2541 | |||
| 2542 | $hA = self::splitRowID($rowID); |
||
| 2543 | $uid = $hA['msgUID']; |
||
| 2544 | $mailbox = $hA['folder']; |
||
| 2545 | $icServerID = $hA['profileID']; |
||
| 2546 | $rememberServerID = $this->mail_bo->profileID; |
||
| 2547 | if ($icServerID && $icServerID != $this->mail_bo->profileID) |
||
| 2548 | { |
||
| 2549 | //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); |
||
| 2550 | $this->changeProfile($icServerID); |
||
| 2551 | } |
||
| 2552 | $part = $_GET['part']; |
||
| 2553 | $is_winmail = $_GET['is_winmail'] ? $_GET['is_winmail'] : 0; |
||
| 2554 | |||
| 2555 | $this->mail_bo->reopen($mailbox); |
||
| 2556 | $attachment = $this->mail_bo->getAttachment($uid,$part,$is_winmail,false); |
||
| 2557 | $this->mail_bo->closeConnection(); |
||
| 2558 | if ($rememberServerID != $this->mail_bo->profileID) |
||
| 2559 | { |
||
| 2560 | //error_log(__METHOD__.__LINE__.' change Profile back to where we came from->'.$rememberServerID); |
||
| 2561 | $this->changeProfile($rememberServerID); |
||
| 2562 | } |
||
| 2563 | |||
| 2564 | $GLOBALS['egw']->session->commit_session(); |
||
| 2565 | //error_log(__METHOD__.print_r($_GET,true)); |
||
| 2566 | if ($_GET['mode'] != "save") |
||
| 2567 | { |
||
| 2568 | View Code Duplication | if (strtoupper($attachment['type']) == 'TEXT/DIRECTORY' || empty($attachment['type'])) |
|
| 2569 | { |
||
| 2570 | $sfxMimeType = $attachment['type']; |
||
| 2571 | $buff = explode('.',$attachment['filename']); |
||
| 2572 | $suffix = ''; |
||
| 2573 | if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime |
||
| 2574 | if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix); |
||
| 2575 | $attachment['type'] = $sfxMimeType; |
||
| 2576 | if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD') $attachment['type'] = strtoupper($sfxMimeType); |
||
| 2577 | } |
||
| 2578 | //error_log(__METHOD__.print_r($attachment,true)); |
||
| 2579 | if (strtoupper($attachment['type']) == 'TEXT/CALENDAR' || strtoupper($attachment['type']) == 'TEXT/X-VCALENDAR') |
||
| 2580 | { |
||
| 2581 | //error_log(__METHOD__."about to call calendar_ical"); |
||
| 2582 | $calendar_ical = new calendar_ical(); |
||
| 2583 | $eventid = $calendar_ical->search($attachment['attachment'],-1); |
||
| 2584 | //error_log(__METHOD__.array2string($eventid)); |
||
| 2585 | if (!$eventid) $eventid = -1; |
||
| 2586 | $event = $calendar_ical->importVCal($attachment['attachment'],(is_array($eventid)?$eventid[0]:$eventid),null,true,0,'',null,$attachment['charset']); |
||
| 2587 | //error_log(__METHOD__.$event); |
||
| 2588 | View Code Duplication | if ((int)$event > 0) |
|
| 2589 | { |
||
| 2590 | $vars = array( |
||
| 2591 | 'menuaction' => 'calendar.calendar_uiforms.edit', |
||
| 2592 | 'cal_id' => $event, |
||
| 2593 | ); |
||
| 2594 | Egw::redirect_link('../index.php',$vars); |
||
| 2595 | } |
||
| 2596 | //Import failed, download content anyway |
||
| 2597 | } |
||
| 2598 | View Code Duplication | if (strtoupper($attachment['type']) == 'TEXT/X-VCARD' || strtoupper($attachment['type']) == 'TEXT/VCARD') |
|
| 2599 | { |
||
| 2600 | $addressbook_vcal = new addressbook_vcal(); |
||
| 2601 | // double \r\r\n seems to end a vcard prematurely, so we set them to \r\n |
||
| 2602 | //error_log(__METHOD__.__LINE__.$attachment['attachment']); |
||
| 2603 | $attachment['attachment'] = str_replace("\r\r\n", "\r\n", $attachment['attachment']); |
||
| 2604 | $vcard = $addressbook_vcal->vcardtoegw($attachment['attachment'], $attachment['charset']); |
||
| 2605 | if ($vcard['uid']) |
||
| 2606 | { |
||
| 2607 | $vcard['uid'] = trim($vcard['uid']); |
||
| 2608 | //error_log(__METHOD__.__LINE__.print_r($vcard,true)); |
||
| 2609 | $contact = $addressbook_vcal->find_contact($vcard,false); |
||
| 2610 | } |
||
| 2611 | if (!$contact) $contact = null; |
||
| 2612 | // if there are not enough fields in the vcard (or the parser was unable to correctly parse the vcard (as of VERSION:3.0 created by MSO)) |
||
| 2613 | if ($contact || count($vcard)>2) |
||
| 2614 | { |
||
| 2615 | $contact = $addressbook_vcal->addVCard($attachment['attachment'],(is_array($contact)?array_shift($contact):$contact),true,$attachment['charset']); |
||
| 2616 | } |
||
| 2617 | if ((int)$contact > 0) |
||
| 2618 | { |
||
| 2619 | $vars = array( |
||
| 2620 | 'menuaction' => 'addressbook.addressbook_ui.edit', |
||
| 2621 | 'contact_id' => $contact, |
||
| 2622 | ); |
||
| 2623 | Egw::redirect_link('../index.php',$vars); |
||
| 2624 | } |
||
| 2625 | //Import failed, download content anyway |
||
| 2626 | } |
||
| 2627 | } |
||
| 2628 | //error_log(__METHOD__.__LINE__.'->'.array2string($attachment)); |
||
| 2629 | $filename = ($attachment['name']?$attachment['name']:($attachment['filename']?$attachment['filename']:$mailbox.'_uid'.$uid.'_part'.$part)); |
||
| 2630 | Api\Header\Content::safe($attachment['attachment'], $filename, $attachment['type'], $size=0, True, $_GET['mode'] == "save"); |
||
| 2631 | echo $attachment['attachment']; |
||
| 2632 | |||
| 2633 | exit(); |
||
| 2634 | } |
||
| 2635 | |||
| 2636 | |||
| 2637 | /** |
||
| 2638 | * save messages on disk or filemanager, or display it in popup |
||
| 2639 | * |
||
| 2640 | * all params are passed as GET Parameters |
||
| 2641 | */ |
||
| 2642 | function saveMessage() |
||
| 2685 | |||
| 2686 | /** |
||
| 2687 | * Save an Message in the vfs |
||
| 2688 | * |
||
| 2689 | * @param string|array $ids use splitRowID, to separate values |
||
| 2690 | * @param string $path path in vfs (no Vfs::PREFIX!), only directory for multiple id's ($ids is an array) |
||
| 2691 | * @param boolean $close Return javascript to close the window |
||
| 2692 | * @return string|boolean javascript eg. to close the selector window if $close is true, or success/fail if $close is false |
||
| 2693 | */ |
||
| 2694 | function vfsSaveMessage($ids,$path, $close = true) |
||
| 2760 | |||
| 2761 | /** |
||
| 2762 | * Save an attachment in the vfs |
||
| 2763 | * |
||
| 2764 | * @param string|array $ids '::' delimited mailbox::uid::part-id::is_winmail::name (::name for multiple id's) |
||
| 2765 | * @param string $path path in vfs (no Vfs::PREFIX!), only directory for multiple id's ($ids is an array) |
||
| 2766 | * @return string javascript eg. to close the selector window |
||
| 2767 | */ |
||
| 2768 | function vfsSaveAttachment($ids,$path) |
||
| 2873 | |||
| 2874 | /** |
||
| 2875 | * Zip all attachments and send to user |
||
| 2876 | * @param string $message_id = null |
||
| 2877 | */ |
||
| 2878 | function download_zip($message_id=null) |
||
| 2879 | { |
||
| 2880 | //error_log(__METHOD__.__LINE__.array2string($_GET)); |
||
| 2881 | // First, get all attachment IDs |
||
| 2882 | if(isset($_GET['id'])) $message_id = $_GET['id']; |
||
| 2883 | //error_log(__METHOD__.__LINE__.$message_id); |
||
| 2884 | $rememberServerID = $this->mail_bo->profileID; |
||
| 2885 | if(!is_numeric($message_id)) |
||
| 2886 | { |
||
| 2887 | $hA = self::splitRowID($message_id); |
||
| 2888 | $message_id = $hA['msgUID']; |
||
| 2889 | $mailbox = $hA['folder']; |
||
| 2890 | $icServerID = $hA['profileID']; |
||
| 2891 | if ($icServerID && $icServerID != $this->mail_bo->profileID) |
||
| 2892 | { |
||
| 2893 | //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); |
||
| 2894 | $this->changeProfile($icServerID); |
||
| 2895 | } |
||
| 2978 | |||
| 2979 | function get_load_email_data($uid, $partID, $mailbox,$htmlOptions=null) |
||
| 3020 | |||
| 3021 | static function get_email_header($additionalStyle='') |
||
| 3036 | |||
| 3037 | function showBody(&$body, $print=true,$fullPageTags=true) |
||
| 3050 | |||
| 3051 | function &getdisplayableBody($_bodyParts,$modifyURI=true,$useTidy = true) |
||
| 3248 | |||
| 3249 | /** |
||
| 3250 | * Resolve inline images from CID to proper url |
||
| 3251 | * |
||
| 3252 | * @param string $_body message content |
||
| 3253 | * @param string $_mailbox mail folder |
||
| 3254 | * @param string $_uid uid |
||
| 3255 | * @param string $_partID part id |
||
| 3256 | * @param string $_messageType = 'html', message type is either html or plain |
||
| 3257 | * @return string message body including all CID images replaced |
||
| 3258 | */ |
||
| 3259 | public static function resolve_inline_images ($_body,$_mailbox, $_uid, $_partID, $_messageType = 'html') |
||
| 3274 | |||
| 3275 | /** |
||
| 3276 | * Replace CID with proper type of content understandable by browser |
||
| 3277 | * |
||
| 3278 | * @param type $_body content of message |
||
| 3279 | * @param type $_mailbox mail box |
||
| 3280 | * @param type $_uid uid |
||
| 3281 | * @param type $_partID part id |
||
| 3282 | * @param type $_type = 'src' type of inline image that needs to be resolved and replaced |
||
| 3283 | * - types: {plain|src|url|background} |
||
| 3284 | * @return string returns body content including all CID replacements |
||
| 3285 | */ |
||
| 3286 | public static function resolve_inline_image_byType ($_body,$_mailbox, $_uid, $_partID, $_type ='src') |
||
| 3390 | |||
| 3391 | /** |
||
| 3392 | * importMessage |
||
| 3393 | * @param array $content = null an array of content |
||
| 3394 | */ |
||
| 3395 | function importMessage($content=null) |
||
| 3459 | |||
| 3460 | /** |
||
| 3461 | * importMessageToFolder |
||
| 3462 | * |
||
| 3463 | * @param array $_formData Array with information of name, type, file and size |
||
| 3464 | * @param string $_folder (passed by reference) will set the folder used. must be set with a folder, but will hold modifications if |
||
| 3465 | * folder is modified |
||
| 3466 | * @param string $importID ID for the imported message, used by attachments to identify them unambiguously |
||
| 3467 | * @return mixed $messageUID or exception |
||
| 3468 | */ |
||
| 3469 | function importMessageToFolder($_formData,&$_folder,$importID='') |
||
| 3537 | |||
| 3538 | /** |
||
| 3539 | * importMessageFromVFS2DraftAndEdit |
||
| 3540 | * |
||
| 3541 | * @param array $formData Array with information of name, type, file and size; file is required, |
||
| 3542 | * name, type and size may be set here to meet the requirements |
||
| 3543 | * Example: $formData['name'] = 'a_email.eml'; |
||
| 3544 | * $formData['type'] = 'message/rfc822'; |
||
| 3545 | * $formData['file'] = 'vfs://default/home/leithoff/a_email.eml'; |
||
| 3546 | * $formData['size'] = 2136; |
||
| 3547 | * @return void |
||
| 3548 | */ |
||
| 3549 | function importMessageFromVFS2DraftAndEdit($formData='') |
||
| 3553 | |||
| 3554 | /** |
||
| 3555 | * importMessageFromVFS2DraftAndDisplay |
||
| 3556 | * |
||
| 3557 | * @param array $formData Array with information of name, type, file and size; file is required, |
||
| 3558 | * name, type and size may be set here to meet the requirements |
||
| 3559 | * Example: $formData['name'] = 'a_email.eml'; |
||
| 3560 | * $formData['type'] = 'message/rfc822'; |
||
| 3561 | * $formData['file'] = 'vfs://default/home/leithoff/a_email.eml'; |
||
| 3562 | * $formData['size'] = 2136; |
||
| 3563 | * @param string $mode mode to open ImportedMessage display and edit are supported |
||
| 3564 | * @return void |
||
| 3565 | */ |
||
| 3566 | function importMessageFromVFS2DraftAndDisplay($formData='',$mode='display') |
||
| 3622 | |||
| 3623 | /** |
||
| 3624 | * loadEmailBody |
||
| 3625 | * |
||
| 3626 | * @param string _messageID UID |
||
| 3627 | * |
||
| 3628 | * @return xajax response |
||
| 3629 | */ |
||
| 3630 | function loadEmailBody($_messageID=null,$_partID=null,$_htmloptions=null) |
||
| 3656 | |||
| 3657 | /** |
||
| 3658 | * ajax_setFolderStatus - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 3659 | * gets the counters and sets the text of a treenode if needed (unread Messages found) |
||
| 3660 | * @param array $_folder folders to refresh its unseen message counters |
||
| 3661 | * @return nothing |
||
| 3662 | */ |
||
| 3663 | function ajax_setFolderStatus($_folder) |
||
| 3709 | |||
| 3710 | /** |
||
| 3711 | * ajax_addFolder - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 3712 | * @param string $_parentFolderName folder to add a folder to |
||
| 3713 | * @param string $_newName new foldername |
||
| 3714 | * @return nothing |
||
| 3715 | */ |
||
| 3716 | function ajax_addFolder($_parentFolderName, $_newName) |
||
| 3819 | |||
| 3820 | /** |
||
| 3821 | * ajax_renameFolder - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 3822 | * @param string $_folderName folder to rename and refresh |
||
| 3823 | * @param string $_newName new foldername |
||
| 3824 | * @return nothing |
||
| 3825 | */ |
||
| 3826 | function ajax_renameFolder($_folderName, $_newName) |
||
| 3959 | |||
| 3960 | /** |
||
| 3961 | * reload node |
||
| 3962 | * |
||
| 3963 | * @param string _folderName folder to reload |
||
| 3964 | * @param boolean $_subscribedOnly = true |
||
| 3965 | * @return void |
||
| 3966 | */ |
||
| 3967 | function ajax_reloadNode($_folderName,$_subscribedOnly=true) |
||
| 4010 | |||
| 4011 | /** |
||
| 4012 | * ResolveWinmail fetches the encoded attachments |
||
| 4013 | * from winmail.dat and will response expected structure back |
||
| 4014 | * to client in order to display them. |
||
| 4015 | * |
||
| 4016 | * Note: this ajax function should only be called via |
||
| 4017 | * nm mail selection as it does not support profile change |
||
| 4018 | * and uses the current available ic_server connection. |
||
| 4019 | * |
||
| 4020 | * @param type $_rowid row id from nm |
||
| 4021 | * |
||
| 4022 | */ |
||
| 4023 | function ajax_resolveWinmail ($_rowid) |
||
| 4042 | |||
| 4043 | /** |
||
| 4044 | * move folder |
||
| 4045 | * |
||
| 4046 | * @param string _folderName folder to vove |
||
| 4047 | * @param string _target target folder |
||
| 4048 | * |
||
| 4049 | * @return void |
||
| 4050 | */ |
||
| 4051 | function ajax_MoveFolder($_folderName, $_target) |
||
| 4178 | |||
| 4179 | /** |
||
| 4180 | * ajax_deleteFolder - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 4181 | * @param string $_folderName folder to delete |
||
| 4182 | * @param boolean $_return = false wheter return the success value (true) or send response to client (false) |
||
| 4183 | * @return nothing |
||
| 4184 | */ |
||
| 4185 | function ajax_deleteFolder($_folderName, $_return = false) |
||
| 4276 | |||
| 4277 | /** |
||
| 4278 | * empty changeProfile - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 4279 | * |
||
| 4280 | * Made static to NOT call __construct, as it would connect to old server, before going to new one |
||
| 4281 | * |
||
| 4282 | * @param int $icServerID New profile / server ID |
||
| 4283 | * @param bool $getFolders The client needs the folders for the profile |
||
| 4284 | * @return nothing |
||
| 4285 | */ |
||
| 4286 | public static function ajax_changeProfile($icServerID, $getFolders = true, $exec_id=null) |
||
| 4318 | |||
| 4319 | /** |
||
| 4320 | * ajax_refreshVacationNotice - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 4321 | * Note: only the activeProfile VacationNotice is refreshed |
||
| 4322 | * @param int $icServerID profileId / server ID to work on; may be empty -> then activeProfile is used |
||
| 4323 | * if other than active profile; nothing is done! |
||
| 4324 | * @return nothing |
||
| 4325 | */ |
||
| 4326 | public static function ajax_refreshVacationNotice($icServerID=null) |
||
| 4367 | |||
| 4368 | /** |
||
| 4369 | * ajax_refreshFilters - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 4370 | * Note: only the activeProfile Filters are refreshed |
||
| 4371 | * @param int $icServerID profileId / server ID to work on; may be empty -> then activeProfile is used |
||
| 4372 | * if other than active profile; nothing is done! |
||
| 4373 | * @return nothing |
||
| 4374 | */ |
||
| 4375 | function ajax_refreshFilters($icServerID=null) |
||
| 4414 | |||
| 4415 | /** |
||
| 4416 | * This function asks quota from IMAP server and makes the |
||
| 4417 | * result as JSON response to send it to mail_sendQuotaDisplay |
||
| 4418 | * function in client side. |
||
| 4419 | * |
||
| 4420 | * @param string $icServerID = null |
||
| 4421 | * |
||
| 4422 | */ |
||
| 4423 | function ajax_refreshQuotaDisplay($icServerID=null) |
||
| 4473 | |||
| 4474 | /** |
||
| 4475 | * Empty spam/junk folder |
||
| 4476 | * |
||
| 4477 | * @param string $icServerID id of the server to empty its junkFolder |
||
| 4478 | * @param string $selectedFolder seleted(active) folder by nm filter |
||
| 4479 | * @return nothing |
||
| 4480 | */ |
||
| 4481 | View Code Duplication | function ajax_emptySpam($icServerID, $selectedFolder) |
|
| 4523 | |||
| 4524 | /** |
||
| 4525 | * Empty trash folder |
||
| 4526 | * |
||
| 4527 | * @param string $icServerID id of the server to empty its trashFolder |
||
| 4528 | * @param string $selectedFolder seleted(active) folder by nm filter |
||
| 4529 | * @return nothing |
||
| 4530 | */ |
||
| 4531 | View Code Duplication | function ajax_emptyTrash($icServerID, $selectedFolder) |
|
| 4573 | |||
| 4574 | /** |
||
| 4575 | * compress folder - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 4576 | * fetches the current folder from session and compresses it |
||
| 4577 | * @param string $_folderName id of the folder to compress |
||
| 4578 | * @return nothing |
||
| 4579 | */ |
||
| 4580 | function ajax_compressFolder($_folderName) |
||
| 4610 | |||
| 4611 | /** |
||
| 4612 | * sendMDN, ... |
||
| 4613 | * |
||
| 4614 | * @param array _messageList list of UID's |
||
| 4615 | * |
||
| 4616 | * @return nothing |
||
| 4617 | */ |
||
| 4618 | function ajax_sendMDN($_messageList) |
||
| 4625 | |||
| 4626 | /** |
||
| 4627 | * flag messages as read, unread, flagged, ... |
||
| 4628 | * |
||
| 4629 | * @param string _flag name of the flag |
||
| 4630 | * @param array _messageList list of UID's |
||
| 4631 | * @param bool _sendJsonResponse tell fuction to send the JsonResponse |
||
| 4632 | * |
||
| 4633 | * @return xajax response |
||
| 4634 | */ |
||
| 4635 | function ajax_flagMessages($_flag, $_messageList, $_sendJsonResponse=true) |
||
| 4823 | |||
| 4824 | /** |
||
| 4825 | * delete messages |
||
| 4826 | * |
||
| 4827 | * @param array _messageList list of UID's |
||
| 4828 | * @param string _forceDeleteMethod - method of deletion to be enforced |
||
| 4829 | * @return xajax response |
||
| 4830 | */ |
||
| 4831 | function ajax_deleteMessages($_messageList,$_forceDeleteMethod=null) |
||
| 4944 | |||
| 4945 | /** |
||
| 4946 | * copy messages |
||
| 4947 | * |
||
| 4948 | * @param array _folderName target folder |
||
| 4949 | * @param array _messageList list of UID's |
||
| 4950 | * @param string _copyOrMove method to use copy or move allowed |
||
| 4951 | * @param string _move2ArchiveMarker marker to indicate if a move 2 archive was triggered |
||
| 4952 | * |
||
| 4953 | * @return xajax response |
||
| 4954 | */ |
||
| 4955 | function ajax_copyMessages($_folderName, $_messageList, $_copyOrMove='copy', $_move2ArchiveMarker='_') |
||
| 5148 | |||
| 5149 | /** |
||
| 5150 | * Autoloading function to load branches of tree node |
||
| 5151 | * of management folder tree |
||
| 5152 | * |
||
| 5153 | * @param type $_id |
||
| 5154 | */ |
||
| 5155 | function ajax_folderMgmtTree_autoloading ($_id = null) |
||
| 5161 | |||
| 5162 | /** |
||
| 5163 | * Main function to handle folder management dialog |
||
| 5164 | * |
||
| 5165 | * @param array $content content of dialog |
||
| 5166 | */ |
||
| 5167 | function folderManagement (array $content = null) |
||
| 5185 | |||
| 5186 | /** |
||
| 5187 | * Function to delete folder for management longTask dialog |
||
| 5188 | * it sends successfully deleted folder as response to be |
||
| 5189 | * used in long task response handler. |
||
| 5190 | * |
||
| 5191 | * @param type $_folderName |
||
| 5192 | */ |
||
| 5193 | function ajax_folderMgmt_delete ($_folderName) |
||
| 5211 | } |
||
| 5212 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: