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 |
||
| 593 | if ($this->mail_bo->mailPreferences['previewPane']) $etpl->setElementAttribute('splitter', 'template', 'mail.index.nosplitter'); |
||
| 594 | |||
| 595 | return $etpl->exec('mail.mail_ui.index',$content,$sel_options,$readonlys,$preserv); |
||
| 596 | } |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Get tree actions / context menu for tree |
||
| 600 | * |
||
| 601 | * Changes here, may require to log out, as $content[self::$nm_index] get stored in session! |
||
| 602 | * @param {boolean} $imap_actions set to false if you want to avoid to talk to the imap-server |
||
| 603 | * @return array |
||
| 604 | */ |
||
| 605 | function get_tree_actions($imap_actions=true) |
||
| 606 | { |
||
| 607 | // Start at 2 so auto-added copy+paste actions show up as second group |
||
| 608 | // Needed because there's no 'select all' action to push things down |
||
| 609 | $group=1; |
||
| 610 | // Set tree actions |
||
| 611 | $tree_actions = array( |
||
| 612 | 'drop_move_mail' => array( |
||
| 613 | 'type' => 'drop', |
||
| 614 | 'acceptedTypes' => 'mail', |
||
| 615 | 'icon' => 'move', |
||
| 616 | 'caption' => 'Move to', |
||
| 617 | 'onExecute' => 'javaScript:app.mail.mail_move' |
||
| 618 | ), |
||
| 619 | 'drop_copy_mail' => array( |
||
| 620 | 'type' => 'drop', |
||
| 621 | 'acceptedTypes' => 'mail', |
||
| 622 | 'icon' => 'copy', |
||
| 623 | 'caption' => 'Copy to', |
||
| 624 | 'onExecute' => 'javaScript:app.mail.mail_copy' |
||
| 625 | ), |
||
| 626 | 'drop_cancel' => array( |
||
| 627 | 'icon' => 'cancel', |
||
| 628 | 'caption' => 'Cancel', |
||
| 629 | 'acceptedTypes' => 'mail', |
||
| 630 | 'type' => 'drop', |
||
| 631 | ), |
||
| 632 | 'drop_move_folder' => array( |
||
| 633 | 'caption' => 'Move folder', |
||
| 634 | 'hideOnDisabled' => true, |
||
| 635 | 'type' => 'drop', |
||
| 636 | 'acceptedTypes' => 'mailFolder', |
||
| 637 | 'onExecute' => 'javaScript:app.mail.mail_MoveFolder' |
||
| 638 | ), |
||
| 639 | // Tree does support this one |
||
| 640 | 'add' => array( |
||
| 641 | 'caption' => 'Add Folder', |
||
| 642 | 'onExecute' => 'javaScript:app.mail.mail_AddFolder', |
||
| 643 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 644 | 'group' => $group, |
||
| 645 | ), |
||
| 646 | 'edit' => array( |
||
| 647 | 'caption' => 'Rename Folder', |
||
| 648 | 'onExecute' => 'javaScript:app.mail.mail_RenameFolder', |
||
| 649 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 650 | 'group' => $group, |
||
| 651 | ), |
||
| 652 | 'move' => array( |
||
| 653 | 'caption' => 'Move Folder', |
||
| 654 | 'type' => 'drag', |
||
| 655 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 656 | 'dragType' => array('mailFolder'), |
||
| 657 | 'group' => $group, |
||
| 658 | ), |
||
| 659 | 'delete' => array( |
||
| 660 | 'caption' => 'Delete Folder', |
||
| 661 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 662 | 'onExecute' => 'javaScript:app.mail.mail_DeleteFolder', |
||
| 663 | 'group' => $group, |
||
| 664 | ), |
||
| 665 | 'subscribe' => array( |
||
| 666 | 'caption' => 'Subscribe folder ...', |
||
| 667 | //'icon' => 'configure', |
||
| 668 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 669 | 'onExecute' => 'javaScript:app.mail.edit_subscribe', |
||
| 670 | 'group' => $group |
||
| 671 | ), |
||
| 672 | 'unsubscribe' => array( |
||
| 673 | 'caption' => 'Unsubscribe folder', |
||
| 674 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 675 | 'onExecute' => 'javaScript:app.mail.unsubscribe_folder', |
||
| 676 | 'group' => $group, |
||
| 677 | ), |
||
| 678 | 'foldermanagement' => array( |
||
| 679 | 'caption' => 'Folder Management ...', |
||
| 680 | 'icon' => 'folder_management', |
||
| 681 | 'enabled' => 'javaScript:app.mail.mail_CheckFolderNoSelect', |
||
| 682 | 'onExecute' => 'javaScript:app.mail.folderManagement', |
||
| 683 | 'group' => $group, |
||
| 684 | 'hideOnMobile' => true |
||
| 685 | ), |
||
| 686 | 'sieve' => array( |
||
| 687 | 'caption' => 'Mail filter', |
||
| 688 | 'onExecute' => 'javaScript:app.mail.edit_sieve', |
||
| 689 | |||
| 690 | 'enabled' => 'javaScript:app.mail.sieve_enabled', |
||
| 691 | 'icon' => 'mail/filter', // funnel |
||
| 692 | 'hideOnMobile' => true |
||
| 693 | ), |
||
| 694 | 'vacation' => array( |
||
| 695 | 'caption' => 'Vacation notice', |
||
| 696 | 'icon' => 'mail/navbar', // mail as in admin |
||
| 697 | 'onExecute' => 'javaScript:app.mail.edit_vacation', |
||
| 698 | 'enabled' => 'javaScript:app.mail.sieve_enabled', |
||
| 699 | ), |
||
| 700 | 'edit_account' => array( |
||
| 701 | 'caption' => 'Edit account ...', |
||
| 702 | 'icon' => 'configure', |
||
| 703 | 'onExecute' => 'javaScript:app.mail.edit_account', |
||
| 704 | ), |
||
| 705 | 'edit_acl' => array( |
||
| 706 | 'caption' => 'Edit folder ACL ...', |
||
| 707 | 'icon' => 'lock', |
||
| 708 | 'enabled' => 'javaScript:app.mail.acl_enabled', |
||
| 709 | 'onExecute' => 'javaScript:app.mail.edit_acl', |
||
| 710 | ), |
||
| 711 | ); |
||
| 712 | // the preference prefaskformove controls actually if there is a popup on target or not |
||
| 713 | // if there are multiple options there is a popup on target, 0 for prefaskformove means |
||
| 714 | // that only move is available; 1 stands for move and cancel; 2 (should be the default if |
||
| 715 | // not set); so we are assuming this, when not set |
||
| 716 | if (isset($this->mail_bo->mailPreferences['prefaskformove'])) |
||
| 717 | { |
||
| 718 | switch ($this->mail_bo->mailPreferences['prefaskformove']) |
||
| 719 | { |
||
| 720 | case 0: |
||
| 721 | unset($tree_actions['drop_copy_mail']); |
||
| 722 | unset($tree_actions['drop_cancel']); |
||
| 723 | break; |
||
| 724 | case 1: |
||
| 725 | unset($tree_actions['drop_copy_mail']); |
||
| 726 | break; |
||
| 727 | default: |
||
| 728 | // everything is fine |
||
| 729 | } |
||
| 730 | } |
||
| 731 | //error_log(__METHOD__.__LINE__.' showAllFoldersInFolderPane:'.$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'].'/'.$GLOBALS['egw_info']['user']['preferences']['mail']['showAllFoldersInFolderPane']); |
||
| 732 | if ($this->mail_bo->mailPreferences['showAllFoldersInFolderPane']) |
||
| 733 | { |
||
| 734 | unset($tree_actions['subscribe']); |
||
| 735 | unset($tree_actions['unsubscribe']); |
||
| 736 | } |
||
| 737 | ++$group; // put delete in own group |
||
| 738 | switch($GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions']) |
||
| 739 | { |
||
| 740 | case 'move_to_trash': |
||
| 741 | $tree_actions['empty_trash'] = array( |
||
| 742 | 'caption' => 'empty trash', |
||
| 743 | 'icon' => 'dhtmlxtree/MailFolderTrash', |
||
| 744 | 'onExecute' => 'javaScript:app.mail.mail_emptyTrash', |
||
| 745 | 'group' => $group, |
||
| 746 | ); |
||
| 747 | break; |
||
| 748 | case 'mark_as_deleted': |
||
| 749 | $tree_actions['compress_folder'] = array( |
||
| 750 | 'caption' => 'compress folder', |
||
| 751 | 'icon' => 'dhtmlxtree/MailFolderTrash', |
||
| 752 | 'onExecute' => 'javaScript:app.mail.mail_compressFolder', |
||
| 753 | 'group' => $group, |
||
| 754 | ); |
||
| 755 | break; |
||
| 756 | } |
||
| 757 | $junkFolder = ($imap_actions?$this->mail_bo->getJunkFolder():null); |
||
| 758 | |||
| 759 | //error_log(__METHOD__.__LINE__.$junkFolder); |
||
| 760 | if ($junkFolder && !empty($junkFolder)) |
||
| 761 | { |
||
| 762 | $tree_actions['empty_spam'] = array( |
||
| 763 | 'caption' => 'empty junk', |
||
| 764 | 'icon' => 'dhtmlxtree/MailFolderJunk', |
||
| 765 | 'enabled' => 'javaScript:app.mail.spamfolder_enabled', |
||
| 766 | 'onExecute' => 'javaScript:app.mail.mail_emptySpam', |
||
| 767 | 'group' => $group, |
||
| 768 | ); |
||
| 769 | } |
||
| 770 | $tree_actions['sieve']['group'] = $tree_actions['vacation']['group'] = ++$group; // new group for filter |
||
| 771 | $tree_actions['edit_account']['group'] = $tree_actions['edit_acl']['group'] = ++$group; |
||
| 772 | |||
| 773 | |||
| 774 | // enforce global (group-specific) ACL |
||
| 775 | if (!mail_hooks::access('aclmanagement')) |
||
| 776 | { |
||
| 777 | unset($tree_actions['edit_acl']); |
||
| 778 | } |
||
| 779 | if (!mail_hooks::access('editfilterrules')) |
||
| 780 | { |
||
| 781 | unset($tree_actions['sieve']); |
||
| 782 | } |
||
| 783 | if (!mail_hooks::access('absentnotice')) |
||
| 784 | { |
||
| 785 | unset($tree_actions['vacation']); |
||
| 786 | } |
||
| 787 | if (!mail_hooks::access('managefolders')) |
||
| 788 | { |
||
| 789 | unset($tree_actions['add']); |
||
| 790 | unset($tree_actions['move']); |
||
| 791 | unset($tree_actions['delete']); |
||
| 792 | unset($tree_actions['foldermanagement']); |
||
| 793 | // manage folders should not affect the ability to subscribe or unsubscribe |
||
| 794 | // to existing folders, it should only affect add/rename/move/delete |
||
| 795 | } |
||
| 796 | return $tree_actions; |
||
| 797 | } |
||
| 798 | |||
| 799 | /** |
||
| 800 | * Ajax callback to subscribe / unsubscribe a Mailbox of an account |
||
| 801 | * |
||
| 802 | * @param {int} $_acc_id profile Id of selected mailbox |
||
| 803 | * @param {string} $_folderName name of mailbox needs to be subcribe or unsubscribed |
||
| 804 | * @param {boolean} $_status set true for subscribe and false to unsubscribe |
||
| 805 | */ |
||
| 806 | public function ajax_foldersubscription($_acc_id,$_folderName, $_status) |
||
| 807 | { |
||
| 808 | //Change the Mail object to related profileId |
||
| 809 | $this->changeProfile($_acc_id); |
||
| 810 | try{ |
||
| 811 | $this->mail_bo->icServer->subscribeMailbox($_folderName, $_status); |
||
| 812 | $this->mail_bo->resetFolderObjectCache($_acc_id); |
||
| 813 | $this->ajax_reloadNode($_acc_id,!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']); |
||
| 814 | } catch (Horde_Imap_Client_Exception $ex) { |
||
| 815 | error_log(__METHOD__.__LINE__."()". lang('Folder %1 %2 failed because of %3!',$_folderName,$_status?'subscribed':'unsubscribed', $ex)); |
||
| 816 | Framework::message(lang('Folder %1 %2 failed!',$_folderName,$_status)); |
||
| 817 | } |
||
| 818 | } |
||
| 819 | |||
| 820 | /** |
||
| 821 | * Ajax callback to fetch folders for given profile |
||
| 822 | * |
||
| 823 | * We currently load all folders of a given profile, tree can also load parts of a tree. |
||
| 824 | * |
||
| 825 | * @param string $_nodeID if of node whos children are requested |
||
| 826 | * @param boolean $_subscribedOnly flag to tell wether to fetch all or only subscribed (default) |
||
| 827 | */ |
||
| 828 | public function ajax_foldertree($_nodeID = null,$_subscribedOnly=null) |
||
| 829 | { |
||
| 830 | $nodeID = $_GET['id']; |
||
| 831 | if (!is_null($_nodeID)) $nodeID = $_nodeID; |
||
| 832 | $subscribedOnly = (bool)(!is_null($_subscribedOnly)?$_subscribedOnly:!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']); |
||
| 833 | $fetchCounters = !is_null($_nodeID); |
||
| 834 | list($_profileID,$_folderName) = explode(self::$delimiter,$nodeID,2); |
||
| 835 | |||
| 836 | if (!empty($_folderName)) $fetchCounters = true; |
||
| 837 | |||
| 838 | // Check if it is called for refresh root |
||
| 839 | // then we need to reinitialized the index tree |
||
| 840 | if(!$nodeID && !$_profileID) |
||
| 841 | { |
||
| 842 | $data = $this->mail_tree->getInitialIndexTree(null,null,null,null,true,!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']); |
||
| 843 | } |
||
| 844 | else |
||
| 845 | { |
||
| 846 | $data = $this->mail_tree->getTree($nodeID,$_profileID,0, false,$subscribedOnly,!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']); |
||
| 847 | } |
||
| 848 | if (!is_null($_nodeID)) return $data; |
||
| 849 | Etemplate\Widget\Tree::send_quote_json($data); |
||
| 850 | } |
||
| 851 | |||
| 852 | /** |
||
| 853 | * findNode - helper function to return only a branch of the tree |
||
| 854 | * |
||
| 855 | * @param array $_out out array (to be searched) |
||
| 856 | * @param string $_nodeID node to search for |
||
| 857 | * @param boolean $childElements return node itself, or only its child items |
||
| 858 | * @return array structured subtree |
||
| 859 | */ |
||
| 860 | static function findNode($_out, $_nodeID, $childElements = false) |
||
| 861 | { |
||
| 862 | foreach($_out['item'] as $node) |
||
| 863 | { |
||
| 864 | if (strcmp($node['id'],$_nodeID)===0) |
||
| 865 | { |
||
| 866 | //error_log(__METHOD__.__LINE__.':'.$_nodeID.'->'.$node['id']); |
||
| 867 | return ($childElements?$node['item']:$node); |
||
| 868 | } |
||
| 869 | elseif (is_array($node['item']) && strncmp($node['id'],$_nodeID,strlen($node['id']))===0 && strlen($_nodeID)>strlen($node['id'])) |
||
| 870 | { |
||
| 871 | //error_log(__METHOD__.__LINE__.' descend into '.$node['id']); |
||
| 872 | return self::findNode($node,$_nodeID,$childElements); |
||
| 873 | } |
||
| 874 | } |
||
| 875 | } |
||
| 876 | |||
| 877 | |||
| 878 | /** |
||
| 879 | * Get actions / context menu for index |
||
| 880 | * |
||
| 881 | * Changes here, require to log out, as $content[self::$nm_index] get stored in session! |
||
| 882 | * @return array see nextmatch_widget::egw_actions() |
||
| 883 | */ |
||
| 884 | private function get_actions() |
||
| 885 | { |
||
| 886 | static $accArray=array(); // buffer identity names on single request |
||
| 887 | // duplicated from mail_hooks |
||
| 888 | static $deleteOptions = array( |
||
| 889 | 'move_to_trash' => 'move to trash', |
||
| 890 | 'mark_as_deleted' => 'mark as deleted', |
||
| 891 | 'remove_immediately' => 'remove immediately', |
||
| 892 | ); |
||
| 893 | // todo: real hierarchical folder list |
||
| 894 | $lastFolderUsedForMove = null; |
||
| 895 | $moveactions = array(); |
||
| 896 | $archiveFolder = $this->mail_bo->getArchiveFolder(); |
||
| 897 | $lastFoldersUsedForMoveCont = Api\Cache::getCache(Api\Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*1); |
||
| 898 | //error_log(__METHOD__.__LINE__." StoredFolders->".array2string($lastFoldersUsedForMoveCont)); |
||
| 899 | //error_log(__METHOD__.__LINE__.' ProfileId:'.$this->mail_bo->profileID." StoredFolders->(".count($lastFoldersUsedForMoveCont[$this->mail_bo->profileID]).") ".array2string($lastFoldersUsedForMoveCont[$this->mail_bo->profileID])); |
||
| 900 | if (is_null($accArray)) |
||
| 901 | { |
||
| 902 | foreach(Mail\Account::search($only_current_user=true, false) as $acc_id => $accountObj) |
||
| 903 | { |
||
| 904 | //error_log(__METHOD__.__LINE__.array2string($accountObj)); |
||
| 905 | if (!$accountObj->is_imap()) |
||
| 906 | { |
||
| 907 | // not to be used for IMAP Foldertree, as there is no Imap host |
||
| 908 | continue; |
||
| 909 | } |
||
| 910 | $identity_name = Mail\Account::identity_name($accountObj,true,$GLOBALS['egw_info']['user']['acount_id']); |
||
| 911 | $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 |
||
| 912 | } |
||
| 913 | } |
||
| 914 | if (!is_array($lastFoldersUsedForMoveCont)) $lastFoldersUsedForMoveCont=array(); |
||
| 915 | foreach (array_keys($lastFoldersUsedForMoveCont) as $pid) |
||
| 916 | { |
||
| 917 | if ($this->mail_bo->profileID==$pid && isset($lastFoldersUsedForMoveCont[$this->mail_bo->profileID])) |
||
| 918 | { |
||
| 919 | $_folder = $this->mail_bo->icServer->getCurrentMailbox(); |
||
| 920 | //error_log(__METHOD__.__LINE__.' '.$_folder."<->".$lastFoldersUsedForMoveCont[$this->mail_bo->profileID].function_backtrace()); |
||
| 921 | $counter =1; |
||
| 922 | foreach ($lastFoldersUsedForMoveCont[$this->mail_bo->profileID] as $i => $lastFolderUsedForMoveCont) |
||
| 923 | { |
||
| 924 | $moveaction = 'move_'; |
||
| 925 | if ($_folder!=$i) |
||
| 926 | { |
||
| 927 | $moveaction .= $lastFolderUsedForMoveCont; |
||
| 928 | //error_log(__METHOD__.__LINE__.'#'.$moveaction); |
||
| 929 | //error_log(__METHOD__.__LINE__.'#'.$currentArchiveActionKey); |
||
| 930 | if ($this->mail_bo->folderExists($i)) // only 10 entries per mailaccount.Control this on setting the buffered folders |
||
| 931 | { |
||
| 932 | $fS['profileID'] = $this->mail_bo->profileID; |
||
| 933 | $fS['profileName'] = $accArray[$this->mail_bo->profileID]; |
||
| 934 | $fS['shortDisplayName'] = $i; |
||
| 935 | $moveactions[$moveaction] = $fS; |
||
| 936 | $counter ++; |
||
| 937 | } |
||
| 938 | else |
||
| 939 | { |
||
| 940 | unset($lastFoldersUsedForMoveCont[$this->mail_bo->profileID][$i]); |
||
| 941 | } |
||
| 942 | //error_log(array2string($moveactions[$moveaction])); |
||
| 943 | } |
||
| 944 | } |
||
| 945 | } |
||
| 946 | elseif ($this->mail_bo->profileID!=$pid && isset($lastFoldersUsedForMoveCont[$pid]) && !empty($lastFoldersUsedForMoveCont[$pid])) |
||
| 947 | { |
||
| 948 | $counter =1; |
||
| 949 | foreach ($lastFoldersUsedForMoveCont[$pid] as $i => $lastFolderUsedForMoveCont) |
||
| 950 | { |
||
| 951 | //error_log(__METHOD__.__LINE__."$i => $lastFolderUsedForMoveCont"); |
||
| 952 | if (!empty($lastFolderUsedForMoveCont)) // only 10 entries per mailaccount.Control this on setting the buffered folders |
||
| 953 | { |
||
| 954 | $moveaction = 'move_'.$lastFolderUsedForMoveCont; |
||
| 955 | //error_log(__METHOD__.__LINE__.'#'.$moveaction); |
||
| 956 | $fS = array(); |
||
| 957 | $fS['profileID'] = $pid; |
||
| 958 | $fS['profileName'] = $accArray[$pid]; |
||
| 959 | $fS['shortDisplayName'] = $i; |
||
| 960 | $moveactions[$moveaction] = $fS; |
||
| 961 | $counter ++; |
||
| 962 | } |
||
| 963 | } |
||
| 964 | } |
||
| 965 | } |
||
| 966 | Api\Cache::setCache(Api\Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']),$lastFoldersUsedForMoveCont, $expiration=60*60*1); |
||
| 967 | $group = 0; |
||
| 968 | $actions = array( |
||
| 969 | 'open' => array( |
||
| 970 | 'caption' => lang('Open'), |
||
| 971 | 'icon' => 'view', |
||
| 972 | 'group' => ++$group, |
||
| 973 | 'onExecute' => Api\Header\UserAgent::mobile()?'javaScript:app.mail.mobileView':'javaScript:app.mail.mail_open', |
||
| 974 | 'allowOnMultiple' => false, |
||
| 975 | 'default' => true, |
||
| 976 | 'mobileViewTemplate' => 'view?'.filemtime(Api\Etemplate\Widget\Template::rel2path('/mail/templates/mobile/view.xet')) |
||
| 977 | ), |
||
| 978 | 'reply' => array( |
||
| 979 | 'caption' => 'Reply', |
||
| 980 | 'icon' => 'mail_reply', |
||
| 981 | 'group' => ++$group, |
||
| 982 | 'onExecute' => 'javaScript:app.mail.mail_compose', |
||
| 983 | 'allowOnMultiple' => false, |
||
| 984 | 'toolbarDefault' => true |
||
| 985 | ), |
||
| 986 | 'reply_all' => array( |
||
| 987 | 'caption' => 'Reply All', |
||
| 988 | 'icon' => 'mail_replyall', |
||
| 989 | 'group' => $group, |
||
| 990 | 'onExecute' => 'javaScript:app.mail.mail_compose', |
||
| 991 | 'allowOnMultiple' => false, |
||
| 992 | ), |
||
| 993 | 'forward' => array( |
||
| 994 | 'caption' => 'Forward', |
||
| 995 | 'icon' => 'mail_forward', |
||
| 996 | 'group' => $group, |
||
| 997 | 'children' => array( |
||
| 998 | 'forwardinline' => array( |
||
| 999 | 'caption' => 'Inline', |
||
| 1000 | 'icon' => 'mail_forward', |
||
| 1001 | 'group' => $group, |
||
| 1002 | 'hint' => 'forward inline', |
||
| 1003 | 'onExecute' => 'javaScript:app.mail.mail_compose', |
||
| 1004 | 'allowOnMultiple' => false, |
||
| 1005 | 'toolbarDefault' => true |
||
| 1006 | ), |
||
| 1007 | 'forwardasattach' => array( |
||
| 1008 | 'caption' => 'Attachment', |
||
| 1009 | 'hint' => 'forward as attachment', |
||
| 1010 | 'icon' => 'mail_forward_attach', |
||
| 1011 | 'group' => $group, |
||
| 1012 | 'onExecute' => 'javaScript:app.mail.mail_compose', |
||
| 1013 | ), |
||
| 1014 | ), |
||
| 1015 | 'hideOnMobile' => true |
||
| 1016 | ), |
||
| 1017 | 'composeasnew' => array( |
||
| 1018 | 'caption' => 'Compose', |
||
| 1019 | 'icon' => 'new', |
||
| 1020 | 'hint' => 'Compose as new', |
||
| 1021 | 'group' => $group, |
||
| 1022 | 'onExecute' => 'javaScript:app.mail.mail_compose', |
||
| 1023 | 'allowOnMultiple' => false, |
||
| 1024 | ) |
||
| 1025 | ); |
||
| 1026 | $macounter=0; |
||
| 1027 | if (!empty($moveactions)) |
||
| 1028 | { |
||
| 1029 | //error_log(__METHOD__.__LINE__.array2string($moveactions)); |
||
| 1030 | $children=array(); |
||
| 1031 | $pID=0; |
||
| 1032 | foreach ($moveactions as $moveaction => $lastFolderUsedForMove) |
||
| 1033 | { |
||
| 1034 | $group = ($pID != $lastFolderUsedForMove['profileID'] && $macounter>0? $group+1 : $group); |
||
| 1035 | //error_log(__METHOD__.__LINE__."#$pID != ".$lastFolderUsedForMove['profileID']."#".$macounter.'#'.$groupCounter.'#'); |
||
| 1036 | $children = array_merge($children, |
||
| 1037 | array( |
||
| 1038 | $moveaction => array( |
||
| 1039 | 'caption' => (!empty($lastFolderUsedForMove['profileName'])?$lastFolderUsedForMove['profileName']:'('.$lastFolderUsedForMove['profileID'].')').': '.(isset($lastFolderUsedForMove['shortDisplayName'])?$lastFolderUsedForMove['shortDisplayName']:''), |
||
| 1040 | 'icon' => 'move', |
||
| 1041 | 'group' => $group, |
||
| 1042 | 'onExecute' => 'javaScript:app.mail.mail_move2folder', |
||
| 1043 | 'allowOnMultiple' => true, |
||
| 1044 | ) |
||
| 1045 | ) |
||
| 1046 | ); |
||
| 1047 | $pID = $lastFolderUsedForMove['profileID']; |
||
| 1048 | $macounter++; |
||
| 1049 | } |
||
| 1050 | $actions['moveto'] = array( |
||
| 1051 | 'caption' => lang('Move selected to'), |
||
| 1052 | 'icon' => 'move', |
||
| 1053 | 'group' => $group, |
||
| 1054 | 'children' => $children, |
||
| 1055 | ); |
||
| 1056 | |||
| 1057 | } else { |
||
| 1058 | $group++; |
||
| 1059 | } |
||
| 1060 | |||
| 1061 | //error_log(__METHOD__.__LINE__.$archiveFolder); |
||
| 1062 | $actions['move2'.$this->mail_bo->profileID.self::$delimiter.$archiveFolder] = array( //toarchive |
||
| 1063 | 'caption' => 'Move to archive', |
||
| 1064 | 'hint' => 'move selected mails to archive', |
||
| 1065 | 'icon' => 'archive', |
||
| 1066 | 'group' => $group++, |
||
| 1067 | 'enabled' => 'javaScript:app.mail.archivefolder_enabled', |
||
| 1068 | //'hideOnDisabled' => true, // does not work as expected on message-list |
||
| 1069 | 'onExecute' => 'javaScript:app.mail.mail_move2folder', |
||
| 1070 | 'shortcut' => KeyManager::shortcut(KeyManager::V, true, true), |
||
| 1071 | 'allowOnMultiple' => true, |
||
| 1072 | 'toolbarDefault' => false |
||
| 1073 | ); |
||
| 1074 | |||
| 1075 | $actions += array( |
||
| 1076 | 'infolog' => array( |
||
| 1077 | 'caption' => 'InfoLog', |
||
| 1078 | 'hint' => 'Save as InfoLog', |
||
| 1079 | 'icon' => 'infolog/navbar', |
||
| 1080 | 'group' => ++$group, |
||
| 1081 | 'onExecute' => 'javaScript:app.mail.mail_integrate', |
||
| 1082 | 'popup' => Link::get_registry('infolog', 'add_popup'), |
||
| 1083 | 'allowOnMultiple' => false, |
||
| 1084 | 'toolbarDefault' => true |
||
| 1085 | ), |
||
| 1086 | 'tracker' => array( |
||
| 1087 | 'caption' => 'Tracker', |
||
| 1088 | 'hint' => 'Save as ticket', |
||
| 1089 | 'group' => $group, |
||
| 1090 | 'icon' => 'tracker/navbar', |
||
| 1091 | 'onExecute' => 'javaScript:app.mail.mail_integrate', |
||
| 1092 | 'popup' => Link::get_registry('tracker', 'add_popup'), |
||
| 1093 | 'mail_import' => Api\Hooks::single(array('location' => 'mail_import'),'tracker'), |
||
| 1094 | 'allowOnMultiple' => false, |
||
| 1095 | ), |
||
| 1096 | 'calendar' => array( |
||
| 1097 | 'caption' => 'Calendar', |
||
| 1098 | 'hint' => 'Save as Calendar', |
||
| 1099 | 'icon' => 'calendar/navbar', |
||
| 1100 | 'group' => $group, |
||
| 1101 | 'onExecute' => 'javaScript:app.mail.mail_integrate', |
||
| 1102 | 'popup' => Link::get_registry('calendar', 'add_popup'), |
||
| 1103 | 'allowOnMultiple' => false, |
||
| 1104 | 'toolbarDefault' => true |
||
| 1105 | ), |
||
| 1106 | 'print' => array( |
||
| 1107 | 'caption' => 'Print', |
||
| 1108 | 'group' => ++$group, |
||
| 1109 | 'onExecute' => 'javaScript:app.mail.mail_print', |
||
| 1110 | 'allowOnMultiple' => false, |
||
| 1111 | 'hideOnMobile' => true |
||
| 1112 | ), |
||
| 1113 | 'save' => array( |
||
| 1114 | 'caption' => 'Save', |
||
| 1115 | 'group' => $group, |
||
| 1116 | 'icon' => 'fileexport', |
||
| 1117 | 'children' => array( |
||
| 1118 | 'save2disk' => array( |
||
| 1119 | 'caption' => 'Save to disk', |
||
| 1120 | 'hint' => 'Save message to disk', |
||
| 1121 | 'group' => $group, |
||
| 1122 | 'icon' => 'fileexport', |
||
| 1123 | 'onExecute' => 'javaScript:app.mail.mail_save', |
||
| 1124 | 'allowOnMultiple' => false, |
||
| 1125 | 'hideOnMobile' => true |
||
| 1126 | ), |
||
| 1127 | 'save2filemanager' => array( |
||
| 1128 | 'caption' => 'Filemanager', |
||
| 1129 | 'hint' => 'Save to filemanager', |
||
| 1130 | 'group' => $group, |
||
| 1131 | 'icon' => 'filemanager/navbar', |
||
| 1132 | 'onExecute' => 'javaScript:app.mail.mail_save2fm', |
||
| 1133 | 'allowOnMultiple' => false, |
||
| 1134 | ), |
||
| 1135 | ), |
||
| 1136 | 'hideOnMobile' => true |
||
| 1137 | ), |
||
| 1138 | 'view' => array( |
||
| 1139 | 'caption' => 'View', |
||
| 1140 | 'group' => $group, |
||
| 1141 | 'icon' => 'kmmsgread', |
||
| 1142 | 'children' => array( |
||
| 1143 | 'header' => array( |
||
| 1144 | 'caption' => 'Header', |
||
| 1145 | 'hint' => 'View header lines', |
||
| 1146 | 'group' => $group, |
||
| 1147 | 'icon' => 'kmmsgread', |
||
| 1148 | 'onExecute' => 'javaScript:app.mail.mail_header', |
||
| 1149 | 'allowOnMultiple' => false, |
||
| 1150 | ), |
||
| 1151 | 'mailsource' => array( |
||
| 1152 | 'caption' => 'Source', |
||
| 1153 | 'hint' => 'View full Mail Source', |
||
| 1154 | 'group' => $group, |
||
| 1155 | 'icon' => 'source', |
||
| 1156 | 'onExecute' => 'javaScript:app.mail.mail_mailsource', |
||
| 1157 | 'allowOnMultiple' => false, |
||
| 1158 | ), |
||
| 1159 | 'openastext' => array( |
||
| 1160 | 'caption' => lang('Text mode'), |
||
| 1161 | 'hint' => 'Open in Text mode', |
||
| 1162 | 'group' => ++$group, |
||
| 1163 | 'icon' => 'textmode', |
||
| 1164 | 'onExecute' => 'javaScript:app.mail.mail_openAsText', |
||
| 1165 | 'allowOnMultiple' => false, |
||
| 1166 | ), |
||
| 1167 | 'openashtml' => array( |
||
| 1168 | 'caption' => lang('HTML mode'), |
||
| 1169 | 'hint' => 'Open in HTML mode', |
||
| 1170 | 'group' => $group, |
||
| 1171 | 'icon' => 'htmlmode', |
||
| 1172 | 'onExecute' => 'javaScript:app.mail.mail_openAsHtml', |
||
| 1173 | 'allowOnMultiple' => false, |
||
| 1174 | ), |
||
| 1175 | ), |
||
| 1176 | 'hideOnMobile' => true |
||
| 1177 | ), |
||
| 1178 | 'mark' => array( |
||
| 1179 | 'caption' => 'Set / Remove Flags', |
||
| 1180 | 'icon' => 'read_small', |
||
| 1181 | 'group' => ++$group, |
||
| 1182 | 'children' => array( |
||
| 1183 | // icons used from http://creativecommons.org/licenses/by-sa/3.0/ |
||
| 1184 | // Artist: Led24 |
||
| 1185 | // Iconset Homepage: http://led24.de/iconset |
||
| 1186 | // License: CC Attribution 3.0 |
||
| 1187 | 'setLabel' => array( |
||
| 1188 | 'caption' => 'Set / Remove Labels', |
||
| 1189 | 'icon' => 'tag_message', |
||
| 1190 | 'group' => ++$group, |
||
| 1191 | // note this one is NOT a real CAPABILITY reported by the server, but added by selectMailbox |
||
| 1192 | 'enabled' => $this->mail_bo->icServer->hasCapability('SUPPORTS_KEYWORDS'), |
||
| 1193 | 'hideOnDisabled' => true, |
||
| 1194 | 'children' => array( |
||
| 1195 | 'unlabel' => array( |
||
| 1196 | 'group' => ++$group, |
||
| 1197 | 'caption' => "<font color='#ff0000'>".lang('remove all')."</font>", |
||
| 1198 | 'icon' => 'mail_label', |
||
| 1199 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1200 | 'shortcut' => KeyManager::shortcut(KeyManager::_0, true, true), |
||
| 1201 | ), |
||
| 1202 | 'label1' => array( |
||
| 1203 | 'group' => ++$group, |
||
| 1204 | 'caption' => "<font color='#ff0000'>".lang('important')."</font>", |
||
| 1205 | 'icon' => 'mail_label1', |
||
| 1206 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1207 | 'shortcut' => KeyManager::shortcut(KeyManager::_1, true, true), |
||
| 1208 | ), |
||
| 1209 | 'label2' => array( |
||
| 1210 | 'group' => $group, |
||
| 1211 | 'caption' => "<font color='#ff8000'>".lang('job')."</font>", |
||
| 1212 | 'icon' => 'mail_label2', |
||
| 1213 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1214 | 'shortcut' => KeyManager::shortcut(KeyManager::_2, true, true), |
||
| 1215 | ), |
||
| 1216 | 'label3' => array( |
||
| 1217 | 'group' => $group, |
||
| 1218 | 'caption' => "<font color='#008000'>".lang('personal')."</font>", |
||
| 1219 | 'icon' => 'mail_label3', |
||
| 1220 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1221 | 'shortcut' => KeyManager::shortcut(KeyManager::_3, true, true), |
||
| 1222 | ), |
||
| 1223 | 'label4' => array( |
||
| 1224 | 'group' => $group, |
||
| 1225 | 'caption' => "<font color='#0000ff'>".lang('to do')."</font>", |
||
| 1226 | 'icon' => 'mail_label4', |
||
| 1227 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1228 | 'shortcut' => KeyManager::shortcut(KeyManager::_4, true, true), |
||
| 1229 | ), |
||
| 1230 | 'label5' => array( |
||
| 1231 | 'group' => $group, |
||
| 1232 | 'caption' => "<font color='#8000ff'>".lang('later')."</font>", |
||
| 1233 | 'icon' => 'mail_label5', |
||
| 1234 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1235 | 'shortcut' => KeyManager::shortcut(KeyManager::_5, true, true), |
||
| 1236 | ), |
||
| 1237 | ), |
||
| 1238 | ), |
||
| 1239 | // modified icons from http://creativecommons.org/licenses/by-sa/3.0/ |
||
| 1240 | 'flagged' => array( |
||
| 1241 | 'group' => ++$group, |
||
| 1242 | 'caption' => 'Flag / Unflag', |
||
| 1243 | 'icon' => 'unread_flagged_small', |
||
| 1244 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1245 | 'hint' => 'Flag or Unflag a mail', |
||
| 1246 | 'shortcut' => KeyManager::shortcut(KeyManager::F, true, true), |
||
| 1247 | 'toolbarDefault' => true |
||
| 1248 | ), |
||
| 1249 | 'read' => array( |
||
| 1250 | 'group' => $group, |
||
| 1251 | 'caption' => 'Read / Unread', |
||
| 1252 | 'icon' => 'read_small', |
||
| 1253 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1254 | 'shortcut' => KeyManager::shortcut(KeyManager::U, true, true), |
||
| 1255 | |||
| 1256 | ), |
||
| 1257 | 'readall' => array( |
||
| 1258 | 'group' => ++$group, |
||
| 1259 | 'caption' => "<font color='#ff0000'>".lang('mark all as read')."</font>", |
||
| 1260 | 'icon' => 'read_small', |
||
| 1261 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1262 | 'hint' => 'mark all messages in folder as read', |
||
| 1263 | 'toolbarDefault' => false |
||
| 1264 | ), |
||
| 1265 | 'undelete' => array( |
||
| 1266 | 'group' => $group, |
||
| 1267 | 'caption' => 'Undelete', |
||
| 1268 | 'icon' => 'revert', |
||
| 1269 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 1270 | ), |
||
| 1271 | ), |
||
| 1272 | ), |
||
| 1273 | 'delete' => array( |
||
| 1274 | 'caption' => 'Delete', |
||
| 1275 | 'hint' => $deleteOptions[$this->mail_bo->mailPreferences['deleteOptions']], |
||
| 1276 | 'group' => ++$group, |
||
| 1277 | 'onExecute' => 'javaScript:app.mail.mail_delete', |
||
| 1278 | 'toolbarDefault' => true |
||
| 1279 | ), |
||
| 1280 | 'drag_mail' => array( |
||
| 1281 | 'dragType' => array('mail'), |
||
| 1282 | 'type' => 'drag', |
||
| 1283 | //'onExecute' => 'javaScript:app.mail.mail_dragStart', |
||
| 1284 | ) |
||
| 1285 | ); |
||
| 1286 | //error_log(__METHOD__.__LINE__.array2string(array_keys($actions))); |
||
| 1287 | // 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 |
||
| 1288 | View Code Duplication | if (!isset($GLOBALS['egw_info']['user']['apps']['infolog'])) |
|
| 1289 | { |
||
| 1290 | unset($actions['infolog']); |
||
| 1291 | } |
||
| 1292 | View Code Duplication | if (!isset($GLOBALS['egw_info']['user']['apps']['tracker'])) |
|
| 1293 | { |
||
| 1294 | unset($actions['tracker']); |
||
| 1295 | } |
||
| 1296 | View Code Duplication | if (!isset($GLOBALS['egw_info']['user']['apps']['calendar'])) |
|
| 1297 | { |
||
| 1298 | unset($actions['calendar']); |
||
| 1299 | } |
||
| 1300 | return $actions; |
||
| 1301 | } |
||
| 1302 | |||
| 1303 | /** |
||
| 1304 | * Callback to fetch the rows for the nextmatch widget |
||
| 1305 | * |
||
| 1306 | * Function is static to not automatic call constructor in case profile is changed. |
||
| 1307 | * |
||
| 1308 | * @param array $query |
||
| 1309 | * @param array &$rows |
||
| 1310 | * @param array &$readonlys |
||
| 1311 | */ |
||
| 1312 | public static function get_rows(&$query,&$rows,&$readonlys) |
||
| 1313 | { |
||
| 1314 | unset($readonlys); // not used, but required by function signature |
||
| 1315 | |||
| 1316 | // handle possible profile change in get_rows |
||
| 1317 | if (!empty($query['selectedFolder'])) |
||
| 1318 | { |
||
| 1319 | list($_profileID,$folderName) = explode(self::$delimiter, $query['selectedFolder'], 2); |
||
| 1320 | if (is_numeric(($_profileID)) && $_profileID != $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']) |
||
| 1321 | { |
||
| 1322 | try { |
||
| 1323 | $mail_ui = new mail_ui(false); // do NOT run constructor, as we change profile anyway |
||
| 1324 | $mail_ui->changeProfile($_profileID); |
||
| 1325 | $query['actions'] = $mail_ui->get_actions(); |
||
| 1326 | } |
||
| 1327 | catch(Exception $e) |
||
| 1328 | { |
||
| 1329 | unset($e); |
||
| 1330 | $rows=array(); |
||
| 1331 | return 0; |
||
| 1332 | } |
||
| 1333 | if (empty($folderName)) $query['selectedFolder'] = $_profileID.self::$delimiter.'INBOX'; |
||
| 1334 | } |
||
| 1335 | } |
||
| 1336 | if (!isset($mail_ui)) |
||
| 1337 | { |
||
| 1338 | try |
||
| 1339 | { |
||
| 1340 | $mail_ui = new mail_ui(true); // run constructor for current profile |
||
| 1341 | } |
||
| 1342 | catch(Exception $e) |
||
| 1343 | { |
||
| 1344 | unset($e); |
||
| 1345 | $rows=array(); |
||
| 1346 | return 0; |
||
| 1347 | } |
||
| 1348 | if (empty($query['selectedFolder'])) $query['selectedFolder'] = $mail_ui->mail_bo->profileID.self::$delimiter.'INBOX'; |
||
| 1349 | } |
||
| 1350 | //error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Start:'.$query['start'].' NumRows:'.$query['num_rows'].array2string($query['order']).'->'.array2string($query['sort'])); |
||
| 1351 | //Mail::$debugTimes=true; |
||
| 1352 | if (Mail::$debugTimes) $starttime = microtime(true); |
||
| 1353 | //$query['search'] is the phrase in the searchbox |
||
| 1354 | |||
| 1355 | $mail_ui->mail_bo->restoreSessionData(); |
||
| 1356 | if (isset($query['selectedFolder'])) $mail_ui->mail_bo->sessionData['mailbox']=$query['selectedFolder']; |
||
| 1357 | |||
| 1358 | $sRToFetch = null; |
||
| 1359 | list($_profileID,$_folderName) = explode(self::$delimiter,$query['selectedFolder'],2); |
||
| 1360 | if (strpos($_folderName,self::$delimiter)!==false) |
||
| 1361 | { |
||
| 1362 | list($app,$_profileID,$_folderName) = explode(self::$delimiter,$_folderName,3); |
||
| 1363 | unset($app); |
||
| 1364 | } |
||
| 1365 | //save selected Folder to sessionData (mailbox)->currentFolder |
||
| 1366 | if (isset($query['selectedFolder'])) $mail_ui->mail_bo->sessionData['mailbox']=$_folderName; |
||
| 1367 | $toSchema = false;//decides to select list schema with column to selected (if false fromaddress is default) |
||
| 1368 | if ($mail_ui->mail_bo->folderExists($_folderName)) |
||
| 1369 | { |
||
| 1370 | $toSchema = $mail_ui->mail_bo->isDraftFolder($_folderName,false)||$mail_ui->mail_bo->isSentFolder($_folderName,false)||$mail_ui->mail_bo->isTemplateFolder($_folderName,false); |
||
| 1371 | } |
||
| 1372 | else |
||
| 1373 | { |
||
| 1374 | // take the extra time on failure |
||
| 1375 | if (!$mail_ui->mail_bo->folderExists($_folderName,true)) |
||
| 1376 | { |
||
| 1377 | //error_log(__METHOD__.__LINE__.' Test on Folder:'.$_folderName.' failed; Using INBOX instead'); |
||
| 1378 | $query['selectedFolder']=$mail_ui->mail_bo->sessionData['mailbox']=$_folderName='INBOX'; |
||
| 1379 | } |
||
| 1380 | } |
||
| 1381 | $mail_ui->mail_bo->saveSessionData(); |
||
| 1382 | $rowsFetched['messages'] = null; |
||
| 1383 | $offset = $query['start']+1; // we always start with 1 |
||
| 1384 | $maxMessages = $query['num_rows']; |
||
| 1385 | //error_log(__METHOD__.__LINE__.array2string($query)); |
||
| 1386 | $sort = ($query['order']=='address'?($toSchema?'toaddress':'fromaddress'):$query['order']); |
||
| 1387 | if (!empty($query['search'])||($query['cat_id']=='bydate' && (!empty($query['startdate'])||!empty($query['enddate'])))) |
||
| 1388 | { |
||
| 1389 | if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID])) |
||
| 1390 | { |
||
| 1391 | Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10); |
||
| 1392 | if (!isset(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID])) |
||
| 1393 | { |
||
| 1394 | Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]=true; |
||
| 1395 | } |
||
| 1396 | } |
||
| 1397 | //error_log(__METHOD__.__LINE__.' Startdate:'.$query['startdate'].' Enddate'.$query['enddate']); |
||
| 1398 | $cutoffdate = $cutoffdate2 = null; |
||
| 1399 | if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'],'ts');//SINCE, enddate |
||
| 1400 | if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate |
||
| 1401 | //error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate); |
||
| 1402 | $filter = array( |
||
| 1403 | 'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')), |
||
| 1404 | 'type' => ($query['cat_id']?$query['cat_id']:(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?'quick':'subject')), |
||
| 1405 | 'string' => $query['search'], |
||
| 1406 | 'status' => 'any', |
||
| 1407 | //'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2) |
||
| 1408 | ); |
||
| 1409 | if ($query['enddate']||$query['startdate']) { |
||
| 1410 | $filter['range'] = "BETWEEN"; |
||
| 1411 | if ($cutoffdate) { |
||
| 1412 | $filter[(empty($cutoffdate2)?'date':'since')] = date("d-M-Y", $cutoffdate); |
||
| 1413 | if (empty($cutoffdate2)) $filter['range'] = "SINCE"; |
||
| 1414 | } |
||
| 1415 | if ($cutoffdate2) { |
||
| 1416 | $filter[(empty($cutoffdate)?'date':'before')] = date("d-M-Y", $cutoffdate2); |
||
| 1417 | if (empty($cutoffdate)) $filter['range'] = "BEFORE"; |
||
| 1418 | } |
||
| 1419 | } |
||
| 1420 | } |
||
| 1421 | else |
||
| 1422 | { |
||
| 1423 | $filter = array(); |
||
| 1424 | } |
||
| 1425 | if ($query['filter']) |
||
| 1426 | { |
||
| 1427 | $filter['status'] = $query['filter']; |
||
| 1428 | } |
||
| 1429 | $reverse = ($query['sort']=='ASC'?false:true); |
||
| 1430 | $prefchanged = false; |
||
| 1431 | View Code Duplication | if (!isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType']) || ($query['cat_id'] !=$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType'])) |
|
| 1432 | { |
||
| 1433 | //error_log(__METHOD__.__LINE__.' Changing userPref ActivesearchType:'.$query['cat_id']); |
||
| 1434 | $GLOBALS['egw']->preferences->add('mail','ActiveSearchType',$query['cat_id'],'user'); |
||
| 1435 | $prefchanged = true; |
||
| 1436 | } |
||
| 1437 | View Code Duplication | if (!isset($GLOBALS['egw_info']['user']['preferences']['mail']['ShowDetails']) || ($query['filter2'] !=$GLOBALS['egw_info']['user']['preferences']['mail']['ShowDetails'])) |
|
| 1438 | { |
||
| 1439 | $GLOBALS['egw']->preferences->add('mail','ShowDetails',$query['filter2'],'user'); |
||
| 1440 | $prefchanged = true; |
||
| 1441 | } |
||
| 1442 | if ($prefchanged) |
||
| 1443 | { |
||
| 1444 | // save prefs |
||
| 1445 | $GLOBALS['egw']->preferences->save_repository(true); |
||
| 1446 | } |
||
| 1447 | //error_log(__METHOD__.__LINE__.' maxMessages:'.$maxMessages.' Offset:'.$offset.' Filter:'.array2string($mail_ui->sessionData['messageFilter'])); |
||
| 1448 | /* |
||
| 1449 | $cutoffdate = Api\DateTime::to('now','ts')-(3600*24*6);//SINCE, enddate |
||
| 1450 | $cutoffdate2 = Api\DateTime::to('now','ts')-(3600*24*3);//BEFORE, startdate |
||
| 1451 | $filter['range'] = "BETWEEN";// we support SINCE, BEFORE, BETWEEN and ON |
||
| 1452 | $filter['since'] = date("d-M-Y", $cutoffdate); |
||
| 1453 | $filter['before']= date("d-M-Y", $cutoffdate2); |
||
| 1454 | */ |
||
| 1455 | try |
||
| 1456 | { |
||
| 1457 | if ($maxMessages > 75) |
||
| 1458 | { |
||
| 1459 | $rByUid = true; |
||
| 1460 | $_sR = $mail_ui->mail_bo->getSortedList( |
||
| 1461 | $_folderName, |
||
| 1462 | $sort, |
||
| 1463 | $reverse, |
||
| 1464 | $filter, |
||
| 1465 | $rByUid |
||
| 1466 | ); |
||
| 1467 | $rowsFetched['messages'] = $_sR['count']; |
||
| 1468 | $ids = $_sR['match']->ids; |
||
| 1469 | // if $sR is false, something failed fundamentally |
||
| 1470 | if($reverse === true) $ids = ($ids===false?array():array_reverse((array)$ids)); |
||
| 1471 | $sR = array_slice((array)$ids,($offset==0?0:$offset-1),$maxMessages); // we need only $maxMessages of uids |
||
| 1472 | $sRToFetch = $sR;//array_slice($sR,0,50); // we fetch only the headers of a subset of the fetched uids |
||
| 1473 | //error_log(__METHOD__.__LINE__.' Rows fetched (UID only):'.count($sR).' Data:'.array2string($sR)); |
||
| 1474 | $maxMessages = 75; |
||
| 1475 | $sortResultwH['header'] = array(); |
||
| 1476 | if (count($sRToFetch)>0) |
||
| 1477 | { |
||
| 1478 | //error_log(__METHOD__.__LINE__.' Headers to fetch with UIDs:'.count($sRToFetch).' Data:'.array2string($sRToFetch)); |
||
| 1479 | $sortResult = array(); |
||
| 1480 | // fetch headers |
||
| 1481 | $sortResultwH = $mail_ui->mail_bo->getHeaders( |
||
| 1482 | $_folderName, |
||
| 1483 | $offset, |
||
| 1484 | $maxMessages, |
||
| 1485 | $sort, |
||
| 1486 | $reverse, |
||
| 1487 | $filter, |
||
| 1488 | $sRToFetch, |
||
| 1489 | true, //cacheResult |
||
| 1490 | ($query['filter2']?true:false) // fetchPreview |
||
| 1491 | ); |
||
| 1492 | } |
||
| 1493 | } |
||
| 1494 | else |
||
| 1495 | { |
||
| 1496 | $sortResult = array(); |
||
| 1497 | // fetch headers |
||
| 1498 | $sortResultwH = $mail_ui->mail_bo->getHeaders( |
||
| 1499 | $_folderName, |
||
| 1500 | $offset, |
||
| 1501 | $maxMessages, |
||
| 1502 | $sort, |
||
| 1503 | $reverse, |
||
| 1504 | $filter, |
||
| 1505 | null, // this uids only |
||
| 1506 | true, // cacheResult |
||
| 1507 | ($query['filter2']?true:false) // fetchPreview |
||
| 1508 | ); |
||
| 1509 | $rowsFetched['messages'] = $sortResultwH['info']['total']; |
||
| 1510 | } |
||
| 1511 | } |
||
| 1512 | catch (Exception $e) |
||
| 1513 | { |
||
| 1514 | $sortResultwH=array(); |
||
| 1515 | $sR=array(); |
||
| 1516 | self::callWizard($e->getMessage(), false, 'error'); |
||
| 1517 | } |
||
| 1518 | $response = Api\Json\Response::get(); |
||
| 1519 | // unlock immediately after fetching the rows |
||
| 1520 | if (stripos($_GET['menuaction'],'ajax_get_rows')!==false) |
||
| 1521 | { |
||
| 1522 | //error_log(__METHOD__.__LINE__.' unlock tree ->'.$_GET['menuaction']); |
||
| 1523 | $response->call('app.mail.unlock_tree'); |
||
| 1524 | } |
||
| 1525 | |||
| 1526 | if (is_array($sR) && count($sR)>0) |
||
| 1527 | { |
||
| 1528 | foreach ((array)$sR as $key => $v) |
||
| 1529 | { |
||
| 1530 | if (array_key_exists($key,(array)$sortResultwH['header'])==true) |
||
| 1531 | { |
||
| 1532 | $sortResult['header'][] = $sortResultwH['header'][$key]; |
||
| 1533 | } |
||
| 1534 | else |
||
| 1535 | { |
||
| 1536 | if (!empty($v)) $sortResult['header'][] = array('uid'=>$v); |
||
| 1537 | } |
||
| 1538 | } |
||
| 1539 | } |
||
| 1540 | else |
||
| 1541 | { |
||
| 1542 | $sortResult = $sortResultwH; |
||
| 1543 | } |
||
| 1544 | $rowsFetched['rowsFetched'] = count($sortResult['header']); |
||
| 1545 | if (empty($rowsFetched['messages'])) $rowsFetched['messages'] = $rowsFetched['rowsFetched']; |
||
| 1546 | |||
| 1547 | //error_log(__METHOD__.__LINE__.' Rows fetched:'.$rowsFetched.' Data:'.array2string($sortResult)); |
||
| 1548 | $cols = array('row_id','uid','status','attachments','subject','address','toaddress','fromaddress','ccaddress','additionaltoaddress','date','size','modified','bodypreview'); |
||
| 1549 | if ($GLOBALS['egw_info']['user']['preferences']['common']['select_mode']=='EGW_SELECTMODE_TOGGLE') unset($cols[0]); |
||
| 1550 | $rows = $mail_ui->header2gridelements($sortResult['header'],$cols, $_folderName, $folderType=$toSchema); |
||
| 1551 | //error_log(__METHOD__.__LINE__.array2string($rows)); |
||
| 1552 | |||
| 1553 | if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'Folder:'.$_folderName.' Start:'.$query['start'].' NumRows:'.$query['num_rows'],__METHOD__.__LINE__); |
||
| 1554 | return $rowsFetched['messages']; |
||
| 1555 | } |
||
| 1556 | |||
| 1557 | /** |
||
| 1558 | * function createRowID - create a unique rowID for the grid |
||
| 1559 | * |
||
| 1560 | * @param string $_folderName used to ensure the uniqueness of the uid over all folders |
||
| 1561 | * @param string $message_uid the message_Uid to be used for creating the rowID |
||
| 1562 | * @param boolean $_prependApp to indicate that the app 'mail' is to be used for creating the rowID |
||
| 1563 | * @return string - a colon separated string in the form [app:]accountID:profileID:folder:message_uid |
||
| 1564 | */ |
||
| 1565 | function createRowID($_folderName, $message_uid, $_prependApp=false) |
||
| 1566 | { |
||
| 1567 | return self::generateRowID($this->mail_bo->profileID, $_folderName, $message_uid, $_prependApp); |
||
| 1568 | } |
||
| 1569 | |||
| 1570 | /** |
||
| 1571 | * static function generateRowID - create a unique rowID for the grid |
||
| 1572 | * |
||
| 1573 | * @param integer $_profileID profile ID for the rowid to be used |
||
| 1574 | * @param string $_folderName to ensure the uniqueness of the uid over all folders |
||
| 1575 | * @param string $message_uid the message_Uid to be used for creating the rowID |
||
| 1576 | * @param boolean $_prependApp to indicate that the app 'mail' is to be used for creating the rowID |
||
| 1577 | * @return string - a colon separated string in the form [app:]accountID:profileID:folder:message_uid |
||
| 1578 | */ |
||
| 1579 | static function generateRowID($_profileID, $_folderName, $message_uid, $_prependApp=false) |
||
| 1580 | { |
||
| 1581 | return ($_prependApp?'mail'.self::$delimiter:'').trim($GLOBALS['egw_info']['user']['account_id']).self::$delimiter.$_profileID.self::$delimiter.base64_encode($_folderName).self::$delimiter.$message_uid; |
||
| 1582 | } |
||
| 1583 | |||
| 1584 | /** |
||
| 1585 | * function splitRowID - split the rowID into its parts |
||
| 1586 | * |
||
| 1587 | * @param string $_rowID string - a colon separated string in the form accountID:profileID:folder:message_uid |
||
| 1588 | * @return array populated named result array (accountID,profileID,folder,msgUID) |
||
| 1589 | */ |
||
| 1590 | static function splitRowID($_rowID) |
||
| 1591 | { |
||
| 1592 | $res = explode(self::$delimiter,$_rowID); |
||
| 1593 | // as a rowID is perceeded by app::, should be mail! |
||
| 1594 | //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)); |
||
| 1595 | if (count($res)==4 && is_numeric($res[0]) ) |
||
| 1596 | { |
||
| 1597 | // we have an own created rowID; prepend app=mail |
||
| 1598 | array_unshift($res,'mail'); |
||
| 1599 | } |
||
| 1600 | return array('app'=>$res[0], 'accountID'=>$res[1], 'profileID'=>$res[2], 'folder'=>base64_decode($res[3]), 'msgUID'=>$res[4]); |
||
| 1601 | } |
||
| 1602 | |||
| 1603 | /** |
||
| 1604 | * Get actions for preview toolbar |
||
| 1605 | * |
||
| 1606 | * @return array |
||
| 1607 | */ |
||
| 1608 | function get_toolbar_actions() |
||
| 1609 | { |
||
| 1610 | $actions = $this->get_actions(); |
||
| 1611 | $arrActions = array('composeasnew', 'reply', 'reply_all', 'forward', 'flagged', 'delete', 'print', |
||
| 1612 | 'infolog', 'tracker', 'calendar', 'save', 'view', 'read', 'label1', 'label2', 'label3', 'label4', 'label5'); |
||
| 1613 | foreach( $arrActions as &$act) |
||
| 1614 | { |
||
| 1615 | //error_log(__METHOD__.__LINE__.' '.$act.'->'.array2string($actions[$act])); |
||
| 1616 | switch ($act) |
||
| 1617 | { |
||
| 1618 | case 'forward': |
||
| 1619 | $actionsenabled[$act]=$actions[$act]; |
||
| 1620 | break; |
||
| 1621 | case 'save': |
||
| 1622 | $actionsenabled[$act]=$actions[$act]; |
||
| 1623 | |||
| 1624 | break; |
||
| 1625 | case 'view': |
||
| 1626 | $actionsenabled[$act]=$actions[$act]; |
||
| 1627 | break; |
||
| 1628 | case 'flagged': |
||
| 1629 | $actionsenabled[$act]= $actions['mark']['children'][$act]; |
||
| 1630 | break; |
||
| 1631 | case 'read': |
||
| 1632 | $actionsenabled[$act]= $actions['mark']['children'][$act]; |
||
| 1633 | break; |
||
| 1634 | View Code Duplication | case 'label1': |
|
| 1635 | $actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('important'); |
||
| 1636 | $actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act]; |
||
| 1637 | break; |
||
| 1638 | View Code Duplication | case 'label2': |
|
| 1639 | $actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('job'); |
||
| 1640 | $actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act]; |
||
| 1641 | break; |
||
| 1642 | View Code Duplication | case 'label3': |
|
| 1643 | $actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('personal'); |
||
| 1644 | $actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act]; |
||
| 1645 | break; |
||
| 1646 | View Code Duplication | case 'label4': |
|
| 1647 | $actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('to do'); |
||
| 1648 | $actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act]; |
||
| 1649 | break; |
||
| 1650 | View Code Duplication | case 'label5': |
|
| 1651 | $actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('later'); |
||
| 1652 | $actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act]; |
||
| 1653 | break; |
||
| 1654 | default: |
||
| 1655 | if (isset($actions[$act])) $actionsenabled[$act]=$actions[$act]; |
||
| 1656 | } |
||
| 1657 | } |
||
| 1658 | unset($actionsenabled['drag_mail']); |
||
| 1659 | //error_log(array2string($actionsenabled['view'])); |
||
| 1660 | unset($actionsenabled['view']['children']['openastext']);//not supported in preview |
||
| 1661 | unset($actionsenabled['view']['children']['openashtml']);//not supported in preview |
||
| 1662 | |||
| 1663 | return $actionsenabled; |
||
| 1664 | } |
||
| 1665 | |||
| 1666 | /** |
||
| 1667 | * function header2gridelements - to populate the grid elements with the collected Data |
||
| 1668 | * |
||
| 1669 | * @param array $_headers headerdata to process |
||
| 1670 | * @param array $cols cols to populate |
||
| 1671 | * @param array $_folderName to ensure the uniqueness of the uid over all folders |
||
| 1672 | * @param array $_folderType used to determine if we need to populate from/to |
||
| 1673 | * @return array populated result array |
||
| 1674 | */ |
||
| 1675 | public function header2gridelements($_headers, $cols, $_folderName, $_folderType=0) |
||
| 1676 | { |
||
| 1677 | if (Mail::$debugTimes) $starttime = microtime(true); |
||
| 1678 | $rv = array(); |
||
| 1679 | $i=0; |
||
| 1680 | foreach((array)$_headers as $header) |
||
| 1681 | { |
||
| 1682 | $i++; |
||
| 1683 | $data = array(); |
||
| 1684 | //error_log(__METHOD__.array2string($header)); |
||
| 1685 | $message_uid = $header['uid']; |
||
| 1686 | $data['uid'] = $message_uid; |
||
| 1687 | $data['row_id']=$this->createRowID($_folderName,$message_uid); |
||
| 1688 | |||
| 1689 | $flags = ""; |
||
| 1690 | if(!empty($header['recent'])) $flags .= "R"; |
||
| 1691 | if(!empty($header['flagged'])) $flags .= "F"; |
||
| 1692 | if(!empty($header['answered'])) $flags .= "A"; |
||
| 1693 | if(!empty($header['forwarded'])) $flags .= "W"; |
||
| 1694 | if(!empty($header['deleted'])) $flags .= "D"; |
||
| 1695 | if(!empty($header['seen'])) $flags .= "S"; |
||
| 1696 | if(!empty($header['label1'])) $flags .= "1"; |
||
| 1697 | if(!empty($header['label2'])) $flags .= "2"; |
||
| 1698 | if(!empty($header['label3'])) $flags .= "3"; |
||
| 1699 | if(!empty($header['label4'])) $flags .= "4"; |
||
| 1700 | if(!empty($header['label5'])) $flags .= "5"; |
||
| 1701 | |||
| 1702 | $data["status"] = "<span class=\"status_img\"></span>"; |
||
| 1703 | //error_log(__METHOD__.array2string($header).' Flags:'.$flags); |
||
| 1704 | |||
| 1705 | // the css for this row |
||
| 1706 | $is_recent=false; |
||
| 1707 | $css_styles = array("mail"); |
||
| 1708 | if ($header['deleted']) { |
||
| 1709 | $css_styles[] = 'deleted'; |
||
| 1710 | } |
||
| 1711 | if ($header['recent'] && !($header['deleted'] || $header['seen'] || $header['answered'] || $header['forwarded'])) { |
||
| 1712 | $css_styles[] = 'recent'; |
||
| 1713 | $is_recent=true; |
||
| 1714 | } |
||
| 1715 | if ($header['priority'] < 3) { |
||
| 1716 | $css_styles[] = 'prio_high'; |
||
| 1717 | } |
||
| 1718 | if ($header['flagged']) { |
||
| 1719 | $css_styles[] = 'flagged'; |
||
| 1720 | } |
||
| 1721 | if (!$header['seen']) { |
||
| 1722 | $css_styles[] = 'unseen'; // different status image for recent // solved via css !important |
||
| 1723 | } |
||
| 1724 | if ($header['answered']) { |
||
| 1725 | $css_styles[] = 'replied'; |
||
| 1726 | } |
||
| 1727 | if ($header['forwarded']) { |
||
| 1728 | $css_styles[] = 'forwarded'; |
||
| 1729 | } |
||
| 1730 | if ($header['label1']) { |
||
| 1731 | $css_styles[] = 'labelone'; |
||
| 1732 | } |
||
| 1733 | if ($header['label2']) { |
||
| 1734 | $css_styles[] = 'labeltwo'; |
||
| 1735 | } |
||
| 1736 | if ($header['label3']) { |
||
| 1737 | $css_styles[] = 'labelthree'; |
||
| 1738 | } |
||
| 1739 | if ($header['label4']) { |
||
| 1740 | $css_styles[] = 'labelfour'; |
||
| 1741 | } |
||
| 1742 | if ($header['label5']) { |
||
| 1743 | $css_styles[] = 'labelfive'; |
||
| 1744 | } |
||
| 1745 | |||
| 1746 | //error_log(__METHOD__.array2string($css_styles)); |
||
| 1747 | |||
| 1748 | if (in_array("subject", $cols)) |
||
| 1749 | { |
||
| 1750 | // filter out undisplayable characters |
||
| 1751 | $search = array('[\016]','[\017]', |
||
| 1752 | '[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]', |
||
| 1753 | '[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]'); |
||
| 1754 | $replace = ''; |
||
| 1755 | |||
| 1756 | $header['subject'] = preg_replace($search,$replace,$header['subject']); |
||
| 1757 | // curly brackets get messed up by the template! |
||
| 1758 | |||
| 1759 | if (!empty($header['subject'])) { |
||
| 1760 | // make the subject shorter if it is to long |
||
| 1761 | $subject = $header['subject']; |
||
| 1762 | } else { |
||
| 1763 | $subject = '('. lang('no subject') .')'; |
||
| 1764 | } |
||
| 1765 | |||
| 1766 | $data["subject"] = $subject; // the mailsubject |
||
| 1767 | } |
||
| 1768 | |||
| 1769 | $imageHTMLBlock = ''; |
||
| 1770 | //error_log(__METHOD__.__LINE__.array2string($header)); |
||
| 1771 | if (in_array("attachments", $cols)) |
||
| 1772 | { |
||
| 1773 | if($header['mimetype'] == 'multipart/mixed' || |
||
| 1774 | $header['mimetype'] == 'multipart/signed' || |
||
| 1775 | $header['mimetype'] == 'multipart/related' || |
||
| 1776 | $header['mimetype'] == 'multipart/report' || |
||
| 1777 | $header['mimetype'] == 'text/calendar' || |
||
| 1778 | $header['mimetype'] == 'text/html' || |
||
| 1779 | substr($header['mimetype'],0,11) == 'application' || |
||
| 1780 | substr($header['mimetype'],0,5) == 'audio' || |
||
| 1781 | substr($header['mimetype'],0,5) == 'video' || |
||
| 1782 | $header['mimetype'] == 'multipart/alternative') |
||
| 1783 | { |
||
| 1784 | $image = Api\Html::image('mail','attach'); |
||
| 1785 | $imageHTMLBlock = ''; |
||
| 1786 | $datarowid = $this->createRowID($_folderName,$message_uid,true); |
||
| 1787 | $attachments = $header['attachments']; |
||
| 1788 | if (count($attachments)<1) |
||
| 1789 | { |
||
| 1790 | $image = ' '; |
||
| 1791 | } |
||
| 1792 | if (count($attachments)==1) |
||
| 1793 | { |
||
| 1794 | $imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'],$_folderName); |
||
| 1795 | $image = Api\Html::image('mail','attach',$attachments[0]['name'].(!empty($attachments[0]['mimeType'])?' ('.$attachments[0]['mimeType'].')':'')); |
||
| 1796 | } |
||
| 1797 | if (count($attachments)>1) |
||
| 1798 | { |
||
| 1799 | $imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'],$_folderName); |
||
| 1800 | $image = Api\Html::image('mail','attach',lang('%1 attachments',count($attachments))); |
||
| 1801 | } |
||
| 1802 | |||
| 1803 | $attachmentFlag = $image; |
||
| 1804 | } else { |
||
| 1805 | $attachmentFlag =' '; |
||
| 1806 | } |
||
| 1807 | // show priority flag |
||
| 1808 | if ($header['priority'] < 3) { |
||
| 1809 | $image = Api\Html::image('mail','prio_high'); |
||
| 1810 | } elseif ($header['priority'] > 3) { |
||
| 1811 | $image = Api\Html::image('mail','prio_low'); |
||
| 1812 | } else { |
||
| 1813 | $image = ''; |
||
| 1814 | } |
||
| 1815 | // show a flag for flagged messages |
||
| 1816 | $imageflagged =''; |
||
| 1817 | if ($header['flagged']) |
||
| 1818 | { |
||
| 1819 | $imageflagged = Api\Html::image('mail','unread_flagged_small'); |
||
| 1820 | } |
||
| 1821 | $data["attachments"] = $image.$attachmentFlag.$imageflagged; // icon for attachments available |
||
| 1822 | } |
||
| 1823 | |||
| 1824 | // sent or draft or template folder -> to address |
||
| 1825 | if (in_array("toaddress", $cols)) |
||
| 1826 | { |
||
| 1827 | // sent or drafts or template folder means foldertype > 0, use to address instead of from |
||
| 1828 | $data["toaddress"] = $header['to_address'];//Mail::htmlentities($header['to_address'],$this->charset); |
||
| 1829 | } |
||
| 1830 | |||
| 1831 | if (in_array("additionaltoaddress", $cols)) |
||
| 1832 | { |
||
| 1833 | $data['additionaltoaddress'] = $header['additional_to_addresses']; |
||
| 1834 | } |
||
| 1835 | //fromaddress |
||
| 1836 | if (in_array("fromaddress", $cols)) |
||
| 1837 | { |
||
| 1838 | $data["fromaddress"] = $header['sender_address']; |
||
| 1839 | } |
||
| 1840 | if (in_array("ccaddress", $cols)) |
||
| 1841 | { |
||
| 1842 | $data['ccaddress'] = $header['cc_addresses']; |
||
| 1843 | } |
||
| 1844 | if (in_array("date", $cols)) |
||
| 1845 | { |
||
| 1846 | $data["date"] = $header['date']; |
||
| 1847 | } |
||
| 1848 | if (in_array("modified", $cols)) |
||
| 1849 | { |
||
| 1850 | $data["modified"] = $header['internaldate']; |
||
| 1851 | } |
||
| 1852 | |||
| 1853 | if (in_array("size", $cols)) |
||
| 1854 | $data["size"] = $header['size']; /// size |
||
| 1855 | |||
| 1856 | $data["class"] = implode(' ', $css_styles); |
||
| 1857 | //translate style-classes back to flags |
||
| 1858 | $data['flags'] = Array(); |
||
| 1859 | if ($header['seen']) $data["flags"]['read'] = 'read'; |
||
| 1860 | foreach ($css_styles as &$flag) { |
||
| 1861 | if ($flag!='mail') |
||
| 1862 | { |
||
| 1863 | if ($flag=='labelone') {$data["flags"]['label1'] = 'label1';} |
||
| 1864 | elseif ($flag=='labeltwo') {$data["flags"]['label2'] = 'label2';} |
||
| 1865 | elseif ($flag=='labelthree') {$data["flags"]['label3'] = 'label3';} |
||
| 1866 | elseif ($flag=='labelfour') {$data["flags"]['label4'] = 'label4';} |
||
| 1867 | elseif ($flag=='labelfive') {$data["flags"]['label5'] = 'label5';} |
||
| 1868 | elseif ($flag=='unseen') {unset($data["flags"]['read']);} |
||
| 1869 | else $data["flags"][$flag] = $flag; |
||
| 1870 | } |
||
| 1871 | } |
||
| 1872 | if ($header['disposition-notification-to']) $data['dispositionnotificationto'] = $header['disposition-notification-to']; |
||
| 1873 | if (($header['mdnsent']||$header['mdnnotsent']|$header['seen'])&&isset($data['dispositionnotificationto'])) unset($data['dispositionnotificationto']); |
||
| 1874 | $data['attachmentsBlock'] = $imageHTMLBlock; |
||
| 1875 | $data['address'] = ($_folderType?$data["toaddress"]:$data["fromaddress"]); |
||
| 1876 | if (in_array("bodypreview", $cols)&&$header['bodypreview']) |
||
| 1877 | { |
||
| 1878 | $data["bodypreview"] = $header['bodypreview']; |
||
| 1879 | } |
||
| 1880 | $rv[] = $data; |
||
| 1881 | //error_log(__METHOD__.__LINE__.array2string($data)); |
||
| 1882 | } |
||
| 1883 | if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'Folder:'.$_folderName,__METHOD__.__LINE__); |
||
| 1884 | |||
| 1885 | // ToDo: call this ONLY if labels change |
||
| 1886 | Etemplate\Widget::setElementAttribute('toolbar', 'actions', $this->get_toolbar_actions()); |
||
| 1887 | |||
| 1888 | return $rv; |
||
| 1889 | } |
||
| 1890 | |||
| 1891 | /** |
||
| 1892 | * display messages header lines |
||
| 1893 | * |
||
| 1894 | * all params are passed as GET Parameters |
||
| 1895 | */ |
||
| 1896 | function displayHeader() |
||
| 1897 | { |
||
| 1898 | if(isset($_GET['id'])) $rowID = $_GET['id']; |
||
| 1899 | if(isset($_GET['part'])) $partID = $_GET['part']; |
||
| 1900 | |||
| 1901 | $hA = self::splitRowID($rowID); |
||
| 1902 | $uid = $hA['msgUID']; |
||
| 1903 | $mailbox = $hA['folder']; |
||
| 1904 | $icServerID = $hA['profileID']; |
||
| 1905 | $rememberServerID = $this->mail_bo->profileID; |
||
| 1906 | if ($icServerID && $icServerID != $this->mail_bo->profileID) |
||
| 1907 | { |
||
| 1908 | //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); |
||
| 1909 | $this->changeProfile($icServerID); |
||
| 1910 | } |
||
| 1911 | |||
| 1912 | $this->mail_bo->reopen($mailbox); |
||
| 1913 | $headers_in = $this->mail_bo->getMessageRawHeader($uid, $partID); |
||
| 1914 | |||
| 1915 | // add line breaks to $rawheaders |
||
| 1916 | $newRawHeaders = explode("\n",$headers_in); |
||
| 1917 | reset($newRawHeaders); |
||
| 1918 | |||
| 1919 | // reset $rawheaders |
||
| 1920 | $rawheaders = ""; |
||
| 1921 | // create it new, with good line breaks |
||
| 1922 | reset($newRawHeaders); |
||
| 1923 | while(list($key,$value) = @each($newRawHeaders)) { |
||
| 1924 | $rawheaders .= wordwrap($value, 90, "\n "); |
||
| 1925 | } |
||
| 1926 | |||
| 1927 | $this->mail_bo->closeConnection(); |
||
| 1928 | if ($rememberServerID != $this->mail_bo->profileID) |
||
| 1929 | { |
||
| 1930 | //error_log(__METHOD__.__LINE__.' change Profile back to where we came from->'.$rememberServerID); |
||
| 1931 | $this->changeProfile($rememberServerID); |
||
| 1932 | } |
||
| 1933 | |||
| 1934 | header('Content-type: text/html; charset=iso-8859-1'); |
||
| 1935 | print '<pre>'. htmlspecialchars($rawheaders, ENT_NOQUOTES, 'iso-8859-1') .'</pre>'; |
||
| 1936 | |||
| 1937 | } |
||
| 1938 | |||
| 1939 | /** |
||
| 1940 | * display messages |
||
| 1941 | * @param array $_requesteddata etemplate content |
||
| 1942 | * all params are passed as GET Parameters, but can be passed via ExecMethod2 as array too |
||
| 1943 | */ |
||
| 1944 | function displayMessage($_requesteddata = null) |
||
| 1945 | { |
||
| 1946 | if (is_null($_requesteddata)) $_requesteddata = $_GET; |
||
| 1947 | |||
| 1948 | $preventRedirect=false; |
||
| 1949 | if(isset($_requesteddata['id'])) $rowID = $_requesteddata['id']; |
||
| 1950 | if(isset($_requesteddata['part'])) $partID = $_requesteddata['part']!='null'?$_requesteddata['part']:null; |
||
| 1951 | if(isset($_requesteddata['mode'])) $preventRedirect = (($_requesteddata['mode']=='display' || $_requesteddata['mode'] == 'print')?true:false); |
||
| 1952 | |||
| 1953 | $hA = self::splitRowID($rowID); |
||
| 1954 | $uid = $hA['msgUID']; |
||
| 1955 | $mailbox = $hA['folder']; |
||
| 1956 | $icServerID = $hA['profileID']; |
||
| 1957 | $rememberServerID = $this->mail_bo->profileID; |
||
| 1958 | if ($icServerID && $icServerID != $this->mail_bo->profileID) |
||
| 1959 | { |
||
| 1960 | //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); |
||
| 1961 | $this->changeProfile($icServerID); |
||
| 1962 | } |
||
| 1963 | $htmlOptions = $this->mail_bo->htmlOptions; |
||
| 1964 | if (!empty($_requesteddata['tryastext'])) $htmlOptions = "only_if_no_text"; |
||
| 1965 | if (!empty($_requesteddata['tryashtml'])) $htmlOptions = "always_display"; |
||
| 1966 | |||
| 1967 | //error_log(__METHOD__.__LINE__.array2string($hA)); |
||
| 1968 | if (($this->mail_bo->isDraftFolder($mailbox)) && $_requesteddata['mode'] == 'print') |
||
| 1969 | { |
||
| 1970 | $response = Api\Json\Response::get(); |
||
| 1971 | $response->call('app.mail.print_for_compose', $rowID); |
||
| 1972 | } |
||
| 1973 | if (!$preventRedirect && ($this->mail_bo->isDraftFolder($mailbox) || $this->mail_bo->isTemplateFolder($mailbox))) |
||
| 1974 | { |
||
| 1975 | Egw::redirect_link('/index.php',array('menuaction'=>'mail.mail_compose.compose','id'=>$rowID,'from'=>'composefromdraft')); |
||
| 1976 | } |
||
| 1977 | $this->mail_bo->reopen($mailbox); |
||
| 1978 | // retrieve the flags of the message, before touching it. |
||
| 1979 | try |
||
| 1980 | { |
||
| 1981 | $headers = $this->mail_bo->getMessageHeader($uid, $partID,true,true,$mailbox); |
||
| 1982 | } |
||
| 1983 | catch (Api\Exception $e) |
||
| 1984 | { |
||
| 1985 | $error_msg[] = lang("ERROR: Message could not be displayed."); |
||
| 1986 | $error_msg[] = lang("In Mailbox: %1, with ID: %2, and PartID: %3",$mailbox,$uid,$partID); |
||
| 1987 | Framework::message($e->getMessage(), 'error'); |
||
| 1988 | } |
||
| 1989 | if (!empty($uid)) $this->mail_bo->getFlags($uid); |
||
| 1990 | $envelope = $this->mail_bo->getMessageEnvelope($uid, $partID,true,$mailbox); |
||
| 1991 | //error_log(__METHOD__.__LINE__.array2string($envelope)); |
||
| 1992 | $this->mail_bo->getMessageRawHeader($uid, $partID,$mailbox); |
||
| 1993 | $fetchEmbeddedImages = false; |
||
| 1994 | // if we are in HTML so its likely that we should show the embedded images; as a result |
||
| 1995 | // we do NOT want to see those, that are embedded in the list of attachments |
||
| 1996 | if ($htmlOptions !='always_display') $fetchEmbeddedImages = true; |
||
| 1997 | $attachments = $this->mail_bo->getMessageAttachments($uid, $partID, null, $fetchEmbeddedImages,true,true,$mailbox); |
||
| 1998 | //error_log(__METHOD__.__LINE__.array2string($attachments)); |
||
| 1999 | $attachmentHTMLBlock = self::createAttachmentBlock($attachments, $rowID, $uid, $mailbox); |
||
| 2000 | |||
| 2001 | $nonDisplayAbleCharacters = array('[\016]','[\017]', |
||
| 2002 | '[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]', |
||
| 2003 | '[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]'); |
||
| 2004 | |||
| 2005 | //error_log(__METHOD__.__LINE__.$mailBody); |
||
| 2006 | $this->mail_bo->closeConnection(); |
||
| 2007 | //$GLOBALS['egw_info']['flags']['currentapp'] = 'mail';//should not be needed |
||
| 2008 | $etpl = new Etemplate('mail.display'); |
||
| 2009 | $subject = $this->mail_bo->decode_subject(preg_replace($nonDisplayAbleCharacters,'',$envelope['SUBJECT']),false); |
||
| 2010 | |||
| 2011 | // Set up data for taglist widget(s) |
||
| 2012 | if ($envelope['FROM']==$envelope['SENDER']) unset($envelope['SENDER']); |
||
| 2013 | $sel_options = array(); |
||
| 2014 | foreach(array('SENDER','FROM','TO','CC','BCC') as $field) |
||
| 2015 | { |
||
| 2016 | if (!isset($envelope[$field])) continue; |
||
| 2017 | foreach($envelope[$field] as $field_data) |
||
| 2018 | { |
||
| 2019 | //error_log(__METHOD__.__LINE__.array2string($field_data)); |
||
| 2020 | $content[$field][] = $field_data; |
||
| 2021 | $sel_options[$field][] = array( |
||
| 2022 | // taglist requires these - not optional |
||
| 2023 | 'id' => $field_data, |
||
| 2024 | 'label' => str_replace('"',"'",$field_data), |
||
| 2025 | ); |
||
| 2026 | } |
||
| 2027 | } |
||
| 2028 | $actionsenabled = $this->getDisplayToolbarActions(); |
||
| 2029 | $content['displayToolbaractions'] = json_encode($actionsenabled); |
||
| 2030 | if (empty($subject)) $subject = lang('no subject'); |
||
| 2031 | $content['msg'] = (is_array($error_msg)?implode("<br>",$error_msg):$error_msg); |
||
| 2032 | // Send mail ID so we can use it for actions |
||
| 2033 | $content['mail_id'] = $rowID; |
||
| 2034 | if (!is_array($headers) || !isset($headers['DATE'])) |
||
| 2035 | { |
||
| 2036 | $headers['DATE'] = (is_array($envelope)&&$envelope['DATE']?$envelope['DATE']:''); |
||
| 2037 | } |
||
| 2038 | $content['mail_displaydate'] = Mail::_strtotime($headers['DATE'],'ts',true); |
||
| 2039 | $content['mail_displaysubject'] = $subject; |
||
| 2040 | $linkData = array('menuaction'=>"mail.mail_ui.loadEmailBody","_messageID"=>$rowID); |
||
| 2041 | if (!empty($partID)) $linkData['_partID']=$partID; |
||
| 2042 | if ($htmlOptions != $this->mail_bo->htmlOptions) $linkData['_htmloptions']=$htmlOptions; |
||
| 2043 | $content['mailDisplayBodySrc'] = Egw::link('/index.php',$linkData); |
||
| 2044 | $content['mail_displayattachments'] = $attachmentHTMLBlock; |
||
| 2045 | $content['mail_id']=$rowID; |
||
| 2046 | $content['mailDisplayContainerClass']=(count($attachments)?"mailDisplayContainer mailDisplayContainerFixedHeight":"mailDisplayContainer mailDisplayContainerFullHeight"); |
||
| 2047 | $content['mailDisplayAttachmentsClass']=(count($attachments)?"mailDisplayAttachments":"mail_DisplayNone"); |
||
| 2048 | |||
| 2049 | // DRAG attachments actions |
||
| 2050 | $etpl->setElementAttribute('mail_displayattachments', 'actions', array( |
||
| 2051 | 'file_drag' => array( |
||
| 2052 | 'dragType' => 'file', |
||
| 2053 | 'type' => 'drag', |
||
| 2054 | 'onExecute' => 'javaScript:app.mail.drag_attachment' |
||
| 2055 | ) |
||
| 2056 | )); |
||
| 2057 | $readonlys = $preserv = $content; |
||
| 2058 | if ($rememberServerID != $this->mail_bo->profileID) |
||
| 2059 | { |
||
| 2060 | //error_log(__METHOD__.__LINE__.' change Profile back to where we came from->'.$rememberServerID); |
||
| 2061 | $this->changeProfile($rememberServerID); |
||
| 2062 | } |
||
| 2063 | |||
| 2064 | $etpl->exec('mail.mail_ui.displayMessage',$content,$sel_options,$readonlys,$preserv,2); |
||
| 2065 | } |
||
| 2066 | |||
| 2067 | /** |
||
| 2068 | * Build actions for display toolbar |
||
| 2069 | */ |
||
| 2070 | function getDisplayToolbarActions () |
||
| 2071 | { |
||
| 2072 | $actions = $this->get_toolbar_actions(); |
||
| 2073 | $actions['mark']['children']['flagged']=array( |
||
| 2074 | 'group' => $actions['mark']['children']['flagged']['group'], |
||
| 2075 | 'caption' => 'Flagged', |
||
| 2076 | 'icon' => 'unread_flagged_small', |
||
| 2077 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 2078 | ); |
||
| 2079 | $actions['mark']['children']['unflagged']=array( |
||
| 2080 | 'group' => $actions['mark']['children']['flagged']['group'], |
||
| 2081 | 'caption' => 'Unflagged', |
||
| 2082 | 'icon' => 'read_flagged_small', |
||
| 2083 | 'onExecute' => 'javaScript:app.mail.mail_flag', |
||
| 2084 | ); |
||
| 2085 | $actions['tracker']['toolbarDefault'] = true; |
||
| 2086 | $actions['forward']['toolbarDefault'] = true; |
||
| 2087 | |||
| 2088 | $compose = $actions['composeasnew']; |
||
| 2089 | unset($actions['composeasnew']); |
||
| 2090 | |||
| 2091 | $actions2 = array_reverse($actions,true); |
||
| 2092 | $actions2['composeasnew']= $compose; |
||
| 2093 | return array_reverse($actions2,true); |
||
| 2094 | } |
||
| 2095 | |||
| 2096 | /** |
||
| 2097 | * helper function to create the attachment block/table |
||
| 2098 | * |
||
| 2099 | * @param array $attachments array with the attachments information |
||
| 2100 | * @param string $rowID rowid of the message |
||
| 2101 | * @param int $uid uid of the message |
||
| 2102 | * @param string $mailbox mailbox identifier |
||
| 2103 | * @param boolean $_returnFullHTML flag wether to return HTML or data array |
||
| 2104 | * @return array|string data array or html or empty string |
||
| 2105 | */ |
||
| 2106 | static function createAttachmentBlock($attachments, $rowID, $uid, $mailbox,$_returnFullHTML=false) |
||
| 2107 | { |
||
| 2108 | $attachmentHTMLBlock=''; |
||
| 2109 | $attachmentHTML = array(); |
||
| 2110 | if (is_array($attachments) && count($attachments) > 0) { |
||
| 2111 | $url_img_vfs = Api\Html::image('filemanager','navbar', lang('Filemanager'), ' height="16"'); |
||
| 2112 | $url_img_vfs_save_all = Api\Html::image('mail','save_all', lang('Save all')); |
||
| 2113 | |||
| 2114 | foreach ($attachments as $key => $value) |
||
| 2115 | { |
||
| 2116 | $attachmentHTML[$key]['filename']= ($value['name'] ? ( $value['filename'] ? $value['filename'] : $value['name'] ) : lang('(no subject)')); |
||
| 2117 | $attachmentHTML[$key]['filename'] = Api\Translation::convert_jsonsafe($attachmentHTML[$key]['filename'],'utf-8'); |
||
| 2118 | //error_log(array2string($value)); |
||
| 2119 | //error_log(strtoupper($value['mimeType']) .'<->'. Api\MimeMagic::filename2mime($attachmentHTML[$key]['filename'])); |
||
| 2120 | if (strtoupper($value['mimeType']=='APPLICATION/OCTET-STREAM')) $value['mimeType'] = Api\MimeMagic::filename2mime($attachmentHTML[$key]['filename']); |
||
| 2121 | $attachmentHTML[$key]['type']=$value['mimeType']; |
||
| 2122 | $attachmentHTML[$key]['mimetype'] = Api\MimeMagic::mime2label($value['mimeType']); |
||
| 2123 | $hA = self::splitRowID($rowID); |
||
| 2124 | $uid = $hA['msgUID']; |
||
| 2125 | $mailbox = $hA['folder']; |
||
| 2126 | $acc_id = $hA['profileID']; |
||
| 2127 | |||
| 2128 | $attachmentHTML[$key]['mime_data'] = Link::set_data($value['mimeType'], 'EGroupware\\Api\\Mail::getAttachmentAccount', array( |
||
| 2129 | $acc_id, $mailbox, $uid, $value['partID'], $value['is_winmail'], true |
||
| 2130 | )); |
||
| 2131 | $attachmentHTML[$key]['size']=Vfs::hsize($value['size']); |
||
| 2132 | $attachmentHTML[$key]['attachment_number']=$key; |
||
| 2133 | $attachmentHTML[$key]['partID']=$value['partID']; |
||
| 2134 | $attachmentHTML[$key]['mail_id'] = $rowID; |
||
| 2135 | $attachmentHTML[$key]['winmailFlag']=$value['is_winmail']; |
||
| 2136 | $attachmentHTML[$key]['classSaveAllPossiblyDisabled'] = "mail_DisplayNone"; |
||
| 2137 | // reset mode array as it should be considered differently for |
||
| 2138 | // each attachment |
||
| 2139 | $mode = array(); |
||
| 2140 | switch(strtoupper($value['mimeType'])) |
||
| 2141 | { |
||
| 2142 | case 'MESSAGE/RFC822': |
||
| 2143 | $linkData = array |
||
| 2144 | ( |
||
| 2145 | 'menuaction' => 'mail.mail_ui.displayMessage', |
||
| 2146 | 'mode' => 'display', //message/rfc822 attachments should be opened in display mode |
||
| 2147 | 'id' => $rowID, |
||
| 2148 | 'part' => $value['partID'], |
||
| 2149 | 'is_winmail' => $value['is_winmail'] |
||
| 2150 | ); |
||
| 2151 | $windowName = 'displayMessage_'. $rowID.'_'.$value['partID']; |
||
| 2152 | $linkView = "egw_openWindowCentered('".Egw::link('/index.php',$linkData)."','$windowName',700,egw_getWindowOuterHeight());"; |
||
| 2153 | break; |
||
| 2154 | case 'IMAGE/JPEG': |
||
| 2155 | case 'IMAGE/PNG': |
||
| 2156 | case 'IMAGE/GIF': |
||
| 2157 | case 'IMAGE/BMP': |
||
| 2158 | // set mode for media mimetypes because we need |
||
| 2159 | // to structure a download url to be used maybe in expose. |
||
| 2160 | $mode = array( |
||
| 2161 | 'mode' => 'save' |
||
| 2162 | ); |
||
| 2163 | case 'APPLICATION/PDF': |
||
| 2164 | case 'TEXT/PLAIN': |
||
| 2165 | case 'TEXT/HTML': |
||
| 2166 | case 'TEXT/DIRECTORY': |
||
| 2167 | $sfxMimeType = $value['mimeType']; |
||
| 2168 | $buff = explode('.',$value['name']); |
||
| 2169 | $suffix = ''; |
||
| 2170 | if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime |
||
| 2171 | if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix); |
||
| 2172 | if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD') |
||
| 2173 | { |
||
| 2174 | $attachments[$key]['mimeType'] = $sfxMimeType; |
||
| 2175 | $value['mimeType'] = strtoupper($sfxMimeType); |
||
| 2176 | } |
||
| 2177 | case 'TEXT/X-VCARD': |
||
| 2178 | case 'TEXT/VCARD': |
||
| 2179 | case 'TEXT/CALENDAR': |
||
| 2180 | case 'TEXT/X-VCALENDAR': |
||
| 2181 | $linkData = array_merge(array |
||
| 2182 | ( |
||
| 2183 | 'menuaction' => 'mail.mail_ui.getAttachment', |
||
| 2184 | 'id' => $rowID, |
||
| 2185 | 'part' => $value['partID'], |
||
| 2186 | 'is_winmail' => $value['is_winmail'], |
||
| 2187 | 'mailbox' => base64_encode($mailbox), |
||
| 2188 | ) , $mode); |
||
| 2189 | $windowName = 'displayAttachment_'. $uid; |
||
| 2190 | $reg = '800x600'; |
||
| 2191 | // handle calendar/vcard |
||
| 2192 | if (strtoupper($value['mimeType'])=='TEXT/CALENDAR') |
||
| 2193 | { |
||
| 2194 | $windowName = 'displayEvent_'. $rowID; |
||
| 2195 | $reg2 = Link::get_registry('calendar','view_popup'); |
||
| 2196 | $attachmentHTML[$key]['popup']=(!empty($reg2) ? $reg2 : $reg); |
||
| 2197 | } |
||
| 2198 | if (strtoupper($value['mimeType'])=='TEXT/X-VCARD' || strtoupper($value['mimeType'])=='TEXT/VCARD') |
||
| 2199 | { |
||
| 2200 | $windowName = 'displayContact_'. $rowID; |
||
| 2201 | $reg2 = Link::get_registry('addressbook','add_popup'); |
||
| 2202 | $attachmentHTML[$key]['popup']=(!empty($reg2) ? $reg2 : $reg); |
||
| 2203 | } |
||
| 2204 | // apply to action |
||
| 2205 | list($width,$height) = explode('x',(!empty($reg2) ? $reg2 : $reg)); |
||
| 2206 | $linkView = "egw_openWindowCentered('".Egw::link('/index.php',$linkData)."','$windowName',$width,$height);"; |
||
| 2207 | break; |
||
| 2208 | default: |
||
| 2209 | $linkData = array |
||
| 2210 | ( |
||
| 2211 | 'menuaction' => 'mail.mail_ui.getAttachment', |
||
| 2212 | 'id' => $rowID, |
||
| 2213 | 'part' => $value['partID'], |
||
| 2214 | 'is_winmail' => $value['is_winmail'], |
||
| 2215 | 'mailbox' => base64_encode($mailbox), |
||
| 2216 | ); |
||
| 2217 | $linkView = "window.location.href = '".Egw::link('/index.php',$linkData)."';"; |
||
| 2218 | break; |
||
| 2219 | } |
||
| 2220 | // we either use mime_data for server-side supported mime-types or mime_url for client-side or download |
||
| 2221 | if (empty($attachmentHTML[$key]['mime_data'])) |
||
| 2222 | { |
||
| 2223 | $attachmentHTML[$key]['mime_url'] = Egw::link('/index.php',$linkData); |
||
| 2224 | unset($attachmentHTML[$key]['mime_data']); |
||
| 2225 | } |
||
| 2226 | $attachmentHTML[$key]['windowName'] = $windowName; |
||
| 2227 | |||
| 2228 | //error_log(__METHOD__.__LINE__.$linkView); |
||
| 2229 | $attachmentHTML[$key]['link_view'] = '<a href="#" ." title="'.$attachmentHTML[$key]['filename'].'" onclick="'.$linkView.' return false;"><b>'. |
||
| 2230 | ($value['name'] ? $value['name'] : lang('(no subject)')). |
||
| 2231 | '</b></a>'; |
||
| 2232 | |||
| 2233 | $linkData = array |
||
| 2234 | ( |
||
| 2235 | 'menuaction' => 'mail.mail_ui.getAttachment', |
||
| 2236 | 'mode' => 'save', |
||
| 2237 | 'id' => $rowID, |
||
| 2238 | 'part' => $value['partID'], |
||
| 2239 | 'is_winmail' => $value['is_winmail'], |
||
| 2240 | 'mailbox' => base64_encode($mailbox), |
||
| 2241 | ); |
||
| 2242 | $attachmentHTML[$key]['link_save'] ="<a href='".Egw::link('/index.php',$linkData)."' title='".$attachmentHTML[$key]['filename']."'>".Api\Html::image('mail','fileexport')."</a>"; |
||
| 2243 | |||
| 2244 | if ($GLOBALS['egw_info']['user']['apps']['filemanager']) |
||
| 2245 | { |
||
| 2246 | $link_vfs_save = Egw::link('/index.php',array( |
||
| 2247 | 'menuaction' => 'filemanager.filemanager_select.select', |
||
| 2248 | 'mode' => 'saveas', |
||
| 2249 | 'name' => $value['name'], |
||
| 2250 | 'mime' => strtolower($value['mimeType']), |
||
| 2251 | 'method' => 'mail.mail_ui.vfsSaveAttachment', |
||
| 2252 | 'id' => $rowID.'::'.$value['partID'].'::'.$value['is_winmail'], |
||
| 2253 | 'label' => lang('Save'), |
||
| 2254 | )); |
||
| 2255 | $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>"; |
||
| 2256 | // add save-all icon for first attachment |
||
| 2257 | if (!$key && count($attachments) > 1) |
||
| 2258 | { |
||
| 2259 | $attachmentHTML[$key]['classSaveAllPossiblyDisabled'] = ""; |
||
| 2260 | foreach ($attachments as $ikey => $value) |
||
| 2261 | { |
||
| 2262 | //$rowID |
||
| 2263 | $ids["id[$ikey]"] = $rowID.'::'.$value['partID'].'::'.$value['is_winmail'].'::'.$value['name']; |
||
| 2264 | } |
||
| 2265 | $link_vfs_save = Egw::link('/index.php',array( |
||
| 2266 | 'menuaction' => 'filemanager.filemanager_select.select', |
||
| 2267 | 'mode' => 'select-dir', |
||
| 2268 | 'method' => 'mail.mail_ui.vfsSaveAttachment', |
||
| 2269 | 'label' => lang('Save all'), |
||
| 2270 | )+$ids); |
||
| 2271 | $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>"; |
||
| 2272 | } |
||
| 2273 | $attachmentHTML[$key]['link_save'] .= $vfs_save; |
||
| 2274 | //error_log(__METHOD__.__LINE__.$attachmentHTML[$key]['link_save']); |
||
| 2275 | } |
||
| 2276 | } |
||
| 2277 | $attachmentHTMLBlock="<table width='100%'>"; |
||
| 2278 | foreach ((array)$attachmentHTML as $row) |
||
| 2279 | { |
||
| 2280 | $attachmentHTMLBlock .= "<tr><td><div class='useEllipsis'>".$row['link_view'].'</div></td>'; |
||
| 2281 | $attachmentHTMLBlock .= "<td>".$row['mimetype'].'</td>'; |
||
| 2282 | $attachmentHTMLBlock .= "<td>".$row['size'].'</td>'; |
||
| 2283 | $attachmentHTMLBlock .= "<td>".$row['link_save'].'</td></tr>'; |
||
| 2284 | } |
||
| 2285 | $attachmentHTMLBlock .= "</table>"; |
||
| 2286 | } |
||
| 2287 | if (!$_returnFullHTML) |
||
| 2288 | { |
||
| 2289 | foreach ((array)$attachmentHTML as $ikey => $value) |
||
| 2290 | { |
||
| 2291 | unset($attachmentHTML[$ikey]['link_view']); |
||
| 2292 | unset($attachmentHTML[$ikey]['link_save']); |
||
| 2293 | } |
||
| 2294 | } |
||
| 2295 | return ($_returnFullHTML?$attachmentHTMLBlock:$attachmentHTML); |
||
| 2296 | } |
||
| 2297 | |||
| 2298 | /** |
||
| 2299 | * fetch vacation info from active Server using icServer object |
||
| 2300 | * |
||
| 2301 | * @param array $cachedVacations an array of cached vacations for an user |
||
| 2302 | * @return array|boolean array with vacation on success or false on failure |
||
| 2303 | */ |
||
| 2304 | function gatherVacation($cachedVacations = array()) |
||
| 2305 | { |
||
| 2306 | $isVacationEnabled = $this->mail_bo->icServer->acc_sieve_enabled && ($this->mail_bo->icServer->acc_sieve_host||$this->mail_bo->icServer->acc_imap_host); |
||
| 2307 | //error_log(__METHOD__.__LINE__.' Server:'.self::$icServerID.' Sieve Enabled:'.array2string($vacation)); |
||
| 2308 | |||
| 2309 | if ($isVacationEnabled) |
||
| 2310 | { |
||
| 2311 | $sieveServer = $this->mail_bo->icServer; |
||
| 2312 | try |
||
| 2313 | { |
||
| 2314 | $sieveServer->retrieveRules(); |
||
| 2315 | $vacation = $sieveServer->getVacation(); |
||
| 2316 | |||
| 2317 | $cachedVacations = array($sieveServer->acc_id => $vacation) + (array)$cachedVacations; |
||
| 2318 | // Set vacation to the instance cache for particular account with expiration of one day |
||
| 2319 | Api\Cache::setCache(Api\Cache::INSTANCE, 'email', 'vacationNotice'.$GLOBALS['egw_info']['user']['account_lid'], $cachedVacations, 60*60*24); |
||
| 2320 | } |
||
| 2321 | catch (PEAR_Exception $ex) |
||
| 2322 | { |
||
| 2323 | $this->callWizard($ex->getMessage(), true, 'error'); |
||
| 2324 | } |
||
| 2325 | } |
||
| 2326 | //error_log(__METHOD__.__LINE__.' Server:'.self::$icServerID.' Vacation retrieved:'.array2string($vacation)); |
||
| 2327 | return $vacation; |
||
| 2328 | } |
||
| 2329 | |||
| 2330 | /** |
||
| 2331 | * gather Info on how to display the quota info |
||
| 2332 | * |
||
| 2333 | * @param int $_usage amount of usage in Kb |
||
| 2334 | * @param int $_limit amount of limit in Kb |
||
| 2335 | * @return array returns an array of info used for quota |
||
| 2336 | * array( |
||
| 2337 | * class => string, |
||
| 2338 | * text => string, |
||
| 2339 | * percent => string, |
||
| 2340 | * freespace => integer |
||
| 2341 | * ) |
||
| 2342 | */ |
||
| 2343 | function quotaDisplay($_usage, $_limit) |
||
| 2344 | { |
||
| 2345 | $percent = $_limit == 0 ? 100 : round(($_usage*100)/$_limit); |
||
| 2346 | $limit = Mail::show_readable_size($_limit*1024); |
||
| 2347 | $usage = Mail::show_readable_size($_usage*1024); |
||
| 2348 | |||
| 2349 | if ($_limit > 0) |
||
| 2350 | { |
||
| 2351 | $text = $usage .'/'.$limit; |
||
| 2352 | switch ($percent) |
||
| 2353 | { |
||
| 2354 | case 90: |
||
| 2355 | $class ='mail-index_QuotaRed'; |
||
| 2356 | break; |
||
| 2357 | case 80: |
||
| 2358 | $class ='mail-index_QuotaYellow'; |
||
| 2359 | break; |
||
| 2360 | default: |
||
| 2361 | $class ='mail-index_QuotaGreen'; |
||
| 2362 | } |
||
| 2363 | } |
||
| 2364 | else |
||
| 2365 | { |
||
| 2366 | $text = $usage; |
||
| 2367 | $class ='mail-index_QuotaGreen'; |
||
| 2368 | } |
||
| 2369 | return array ( |
||
| 2370 | 'class' => $class, |
||
| 2371 | 'text' => lang('Quota: %1',$text), |
||
| 2372 | 'percent' => $percent, |
||
| 2373 | 'freespace' => $_limit*1024 - $_usage*1024 |
||
| 2374 | ); |
||
| 2375 | } |
||
| 2376 | |||
| 2377 | /** |
||
| 2378 | * display image |
||
| 2379 | * |
||
| 2380 | * all params are passed as GET Parameters |
||
| 2381 | */ |
||
| 2382 | function displayImage() |
||
| 2383 | { |
||
| 2384 | $uid = $_GET['uid']; |
||
| 2385 | $cid = base64_decode($_GET['cid']); |
||
| 2386 | $partID = urldecode($_GET['partID']); |
||
| 2387 | if (!empty($_GET['mailbox'])) $mailbox = base64_decode($_GET['mailbox']); |
||
| 2388 | |||
| 2389 | //error_log(__METHOD__.__LINE__.":$uid, $cid, $partID"); |
||
| 2390 | $this->mail_bo->reopen($mailbox); |
||
| 2391 | |||
| 2392 | $attachment = $this->mail_bo->getAttachmentByCID($uid, $cid, $partID, true); // true get contents as stream |
||
| 2393 | |||
| 2394 | $this->mail_bo->closeConnection(); |
||
| 2395 | |||
| 2396 | $GLOBALS['egw']->session->commit_session(); |
||
| 2397 | |||
| 2398 | if ($attachment) |
||
| 2399 | { |
||
| 2400 | header("Content-Type: ". $attachment->getType()); |
||
| 2401 | header('Content-Disposition: inline; filename="'. $attachment->getDispositionParameter('filename') .'"'); |
||
| 2402 | //header("Expires: 0"); |
||
| 2403 | // the next headers are for IE and SSL |
||
| 2404 | //header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
||
| 2405 | //header("Pragma: public"); |
||
| 2406 | Api\Session::cache_control(true); |
||
| 2407 | echo $attachment->getContents(); |
||
| 2408 | } |
||
| 2409 | else |
||
| 2410 | { |
||
| 2411 | // send a 404 Not found |
||
| 2412 | header("HTTP/1.1 404 Not found"); |
||
| 2413 | } |
||
| 2414 | exit(); |
||
| 2415 | } |
||
| 2416 | |||
| 2417 | function getAttachment() |
||
| 2418 | { |
||
| 2419 | if(isset($_GET['id'])) $rowID = $_GET['id']; |
||
| 2420 | |||
| 2421 | $hA = self::splitRowID($rowID); |
||
| 2422 | $uid = $hA['msgUID']; |
||
| 2423 | $mailbox = $hA['folder']; |
||
| 2424 | $icServerID = $hA['profileID']; |
||
| 2425 | $rememberServerID = $this->mail_bo->profileID; |
||
| 2426 | if ($icServerID && $icServerID != $this->mail_bo->profileID) |
||
| 2427 | { |
||
| 2428 | //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); |
||
| 2429 | $this->changeProfile($icServerID); |
||
| 2430 | } |
||
| 2431 | $part = $_GET['part']; |
||
| 2432 | $is_winmail = $_GET['is_winmail'] ? $_GET['is_winmail'] : 0; |
||
| 2433 | |||
| 2434 | $this->mail_bo->reopen($mailbox); |
||
| 2435 | $attachment = $this->mail_bo->getAttachment($uid,$part,$is_winmail,false); |
||
| 2436 | $this->mail_bo->closeConnection(); |
||
| 2437 | if ($rememberServerID != $this->mail_bo->profileID) |
||
| 2438 | { |
||
| 2439 | //error_log(__METHOD__.__LINE__.' change Profile back to where we came from->'.$rememberServerID); |
||
| 2440 | $this->changeProfile($rememberServerID); |
||
| 2441 | } |
||
| 2442 | |||
| 2443 | $GLOBALS['egw']->session->commit_session(); |
||
| 2444 | //error_log(__METHOD__.print_r($_GET,true)); |
||
| 2445 | if ($_GET['mode'] != "save") |
||
| 2446 | { |
||
| 2447 | View Code Duplication | if (strtoupper($attachment['type']) == 'TEXT/DIRECTORY' || empty($attachment['type'])) |
|
| 2448 | { |
||
| 2449 | $sfxMimeType = $attachment['type']; |
||
| 2450 | $buff = explode('.',$attachment['filename']); |
||
| 2451 | $suffix = ''; |
||
| 2452 | if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime |
||
| 2453 | if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix); |
||
| 2454 | $attachment['type'] = $sfxMimeType; |
||
| 2455 | if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD') $attachment['type'] = strtoupper($sfxMimeType); |
||
| 2456 | } |
||
| 2457 | //error_log(__METHOD__.print_r($attachment,true)); |
||
| 2458 | if (strtoupper($attachment['type']) == 'TEXT/CALENDAR' || strtoupper($attachment['type']) == 'TEXT/X-VCALENDAR') |
||
| 2459 | { |
||
| 2460 | //error_log(__METHOD__."about to call calendar_ical"); |
||
| 2461 | $calendar_ical = new calendar_ical(); |
||
| 2462 | $eventid = $calendar_ical->search($attachment['attachment'],-1); |
||
| 2463 | //error_log(__METHOD__.array2string($eventid)); |
||
| 2464 | if (!$eventid) $eventid = -1; |
||
| 2465 | $event = $calendar_ical->importVCal($attachment['attachment'],(is_array($eventid)?$eventid[0]:$eventid),null,true,0,'',null,$attachment['charset']); |
||
| 2466 | //error_log(__METHOD__.$event); |
||
| 2467 | View Code Duplication | if ((int)$event > 0) |
|
| 2468 | { |
||
| 2469 | $vars = array( |
||
| 2470 | 'menuaction' => 'calendar.calendar_uiforms.edit', |
||
| 2471 | 'cal_id' => $event, |
||
| 2472 | ); |
||
| 2473 | Egw::redirect_link('../index.php',$vars); |
||
| 2474 | } |
||
| 2475 | //Import failed, download content anyway |
||
| 2476 | } |
||
| 2477 | View Code Duplication | if (strtoupper($attachment['type']) == 'TEXT/X-VCARD' || strtoupper($attachment['type']) == 'TEXT/VCARD') |
|
| 2478 | { |
||
| 2479 | $addressbook_vcal = new addressbook_vcal(); |
||
| 2480 | // double \r\r\n seems to end a vcard prematurely, so we set them to \r\n |
||
| 2481 | //error_log(__METHOD__.__LINE__.$attachment['attachment']); |
||
| 2482 | $attachment['attachment'] = str_replace("\r\r\n", "\r\n", $attachment['attachment']); |
||
| 2483 | $vcard = $addressbook_vcal->vcardtoegw($attachment['attachment'], $attachment['charset']); |
||
| 2484 | if ($vcard['uid']) |
||
| 2485 | { |
||
| 2486 | $vcard['uid'] = trim($vcard['uid']); |
||
| 2487 | //error_log(__METHOD__.__LINE__.print_r($vcard,true)); |
||
| 2488 | $contact = $addressbook_vcal->find_contact($vcard,false); |
||
| 2489 | } |
||
| 2490 | if (!$contact) $contact = null; |
||
| 2491 | // 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)) |
||
| 2492 | if ($contact || count($vcard)>2) |
||
| 2493 | { |
||
| 2494 | $contact = $addressbook_vcal->addVCard($attachment['attachment'],(is_array($contact)?array_shift($contact):$contact),true,$attachment['charset']); |
||
| 2495 | } |
||
| 2496 | if ((int)$contact > 0) |
||
| 2497 | { |
||
| 2498 | $vars = array( |
||
| 2499 | 'menuaction' => 'addressbook.addressbook_ui.edit', |
||
| 2500 | 'contact_id' => $contact, |
||
| 2501 | ); |
||
| 2502 | Egw::redirect_link('../index.php',$vars); |
||
| 2503 | } |
||
| 2504 | //Import failed, download content anyway |
||
| 2505 | } |
||
| 2506 | } |
||
| 2507 | //error_log(__METHOD__.__LINE__.'->'.array2string($attachment)); |
||
| 2508 | $filename = ($attachment['name']?$attachment['name']:($attachment['filename']?$attachment['filename']:$mailbox.'_uid'.$uid.'_part'.$part)); |
||
| 2509 | Api\Header\Content::safe($attachment['attachment'], $filename, $attachment['type'], $size=0, True, $_GET['mode'] == "save"); |
||
| 2510 | echo $attachment['attachment']; |
||
| 2511 | |||
| 2512 | exit(); |
||
| 2513 | } |
||
| 2514 | |||
| 2515 | |||
| 2516 | /** |
||
| 2517 | * save messages on disk or filemanager, or display it in popup |
||
| 2518 | * |
||
| 2519 | * all params are passed as GET Parameters |
||
| 2520 | */ |
||
| 2521 | function saveMessage() |
||
| 2522 | { |
||
| 2523 | $display = false; |
||
| 2524 | if(isset($_GET['id'])) $rowID = $_GET['id']; |
||
| 2525 | if(isset($_GET['part'])) $partID = $_GET['part']; |
||
| 2526 | if (isset($_GET['location'])&& ($_GET['location']=='display'||$_GET['location']=='filemanager')) $display = $_GET['location']; |
||
| 2527 | |||
| 2528 | $hA = self::splitRowID($rowID); |
||
| 2529 | $uid = $hA['msgUID']; |
||
| 2530 | $mailbox = $hA['folder']; |
||
| 2531 | $icServerID = $hA['profileID']; |
||
| 2532 | $rememberServerID = $this->mail_bo->profileID; |
||
| 2533 | if ($icServerID && $icServerID != $this->mail_bo->profileID) |
||
| 2534 | { |
||
| 2535 | //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); |
||
| 2536 | $this->changeProfile($icServerID); |
||
| 2537 | } |
||
| 2538 | |||
| 2539 | $this->mail_bo->reopen($mailbox); |
||
| 2540 | |||
| 2541 | $message = $this->mail_bo->getMessageRawBody($uid, $partID, $mailbox); |
||
| 2542 | |||
| 2543 | $this->mail_bo->closeConnection(); |
||
| 2544 | if ($rememberServerID != $this->mail_bo->profileID) |
||
| 2545 | { |
||
| 2546 | //error_log(__METHOD__.__LINE__.' change Profile back to where we came from ->'.$rememberServerID); |
||
| 2547 | $this->changeProfile($rememberServerID); |
||
| 2548 | } |
||
| 2549 | |||
| 2550 | $GLOBALS['egw']->session->commit_session(); |
||
| 2551 | if (!$display) |
||
| 2552 | { |
||
| 2553 | $headers = Horde_Mime_Headers::parseHeaders($message); |
||
| 2554 | $subject = str_replace('$$','__',Mail::decode_header($headers['SUBJECT'])); |
||
| 2555 | Api\Header\Content::safe($message, $subject.".eml", $mime='message/rfc822', $size=0, true, true); |
||
| 2556 | echo $message; |
||
| 2557 | } |
||
| 2558 | else |
||
| 2559 | { |
||
| 2560 | Api\Header\Content::safe($message, $subject.".eml", $mime='text/html', $size=0, true, false); |
||
| 2561 | print '<pre>'. htmlspecialchars($message, ENT_NOQUOTES|ENT_SUBSTITUTE, 'utf-8') .'</pre>'; |
||
| 2562 | } |
||
| 2563 | } |
||
| 2564 | |||
| 2565 | /** |
||
| 2566 | * Save an Message in the vfs |
||
| 2567 | * |
||
| 2568 | * @param string|array $ids use splitRowID, to separate values |
||
| 2569 | * @param string $path path in vfs (no Vfs::PREFIX!), only directory for multiple id's ($ids is an array) |
||
| 2570 | * @param boolean $close Return javascript to close the window |
||
| 2571 | * @return string|boolean javascript eg. to close the selector window if $close is true, or success/fail if $close is false |
||
| 2572 | */ |
||
| 2573 | function vfsSaveMessage($ids,$path, $close = true) |
||
| 2574 | { |
||
| 2575 | //error_log(__METHOD__.' IDs:'.array2string($ids).' SaveToPath:'.$path); |
||
| 2576 | |||
| 2577 | View Code Duplication | if (is_array($ids) && !Vfs::is_writable($path) || !is_array($ids) && !Vfs::is_writable(dirname($path))) |
|
| 2578 | { |
||
| 2579 | return 'alert("'.addslashes(lang('%1 is NOT writable by you!',$path)).'"); Egw(window).close();'; |
||
| 2580 | } |
||
| 2581 | Api\Translation::add_app('mail'); |
||
| 2582 | |||
| 2583 | $rememberServerID = $this->mail_bo->profileID; |
||
| 2584 | foreach((array)$ids as $id) |
||
| 2585 | { |
||
| 2586 | $hA = self::splitRowID($id); |
||
| 2587 | $uid = $hA['msgUID']; |
||
| 2588 | $mailbox = $hA['folder']; |
||
| 2589 | $icServerID = $hA['profileID']; |
||
| 2590 | if ($icServerID && $icServerID != $this->mail_bo->profileID) |
||
| 2591 | { |
||
| 2592 | //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); |
||
| 2593 | $this->changeProfile($icServerID); |
||
| 2594 | } |
||
| 2595 | $message = $this->mail_bo->getMessageRawBody($uid, $partID='', $mailbox); |
||
| 2596 | $err=null; |
||
| 2597 | if(Vfs::is_dir($path)) |
||
| 2598 | { |
||
| 2599 | $headers = $this->mail_bo->getMessageHeader($uid,$partID,true,false,$mailbox); |
||
| 2600 | $file = $path . '/'.preg_replace('/[\f\n\t\v\\:*#?<>\|]/',"_",$headers['SUBJECT']).'.eml'; |
||
| 2601 | } |
||
| 2602 | else |
||
| 2603 | { |
||
| 2604 | $file = $path; |
||
| 2605 | } |
||
| 2606 | if (!($fp = Vfs::fopen($file,'wb')) || !fwrite($fp,$message)) |
||
| 2607 | { |
||
| 2608 | $err .= lang('Error saving %1!',$file); |
||
| 2609 | $succeeded = false; |
||
| 2610 | } |
||
| 2611 | else |
||
| 2612 | { |
||
| 2613 | $succeeded = true; |
||
| 2614 | } |
||
| 2615 | if ($fp) fclose($fp); |
||
| 2616 | if ($succeeded) |
||
| 2617 | { |
||
| 2618 | unset($headers['SUBJECT']);//already in filename |
||
| 2619 | $infoSection = Mail::createHeaderInfoSection($headers, 'SUPPRESS', false); |
||
| 2620 | $props = array(array('name' => 'comment','val' => $infoSection)); |
||
| 2621 | Vfs::proppatch($file,$props); |
||
| 2622 | } |
||
| 2623 | } |
||
| 2624 | if ($rememberServerID != $this->mail_bo->profileID) |
||
| 2625 | { |
||
| 2626 | //error_log(__METHOD__.__LINE__.' change Profile back to where we came from ->'.$rememberServerID); |
||
| 2627 | $this->changeProfile($rememberServerID); |
||
| 2628 | } |
||
| 2629 | |||
| 2630 | if($close) |
||
| 2631 | { |
||
| 2632 | Framework::window_close(($err?$err:null)); |
||
| 2633 | } |
||
| 2634 | else |
||
| 2635 | { |
||
| 2636 | return $succeeded; |
||
| 2637 | } |
||
| 2638 | } |
||
| 2639 | |||
| 2640 | /** |
||
| 2641 | * Save an attachment in the vfs |
||
| 2642 | * |
||
| 2643 | * @param string|array $ids '::' delimited mailbox::uid::part-id::is_winmail::name (::name for multiple id's) |
||
| 2644 | * @param string $path path in vfs (no Vfs::PREFIX!), only directory for multiple id's ($ids is an array) |
||
| 2645 | * @return string javascript eg. to close the selector window |
||
| 2646 | */ |
||
| 2647 | function vfsSaveAttachment($ids,$path) |
||
| 2648 | { |
||
| 2649 | //error_log(__METHOD__.__LINE__.'("'.array2string($ids).'","'.$path."\")');"); |
||
| 2650 | |||
| 2651 | View Code Duplication | if (is_array($ids) && !Vfs::is_writable($path) || !is_array($ids) && !Vfs::is_writable(dirname($path))) |
|
| 2652 | { |
||
| 2653 | return 'alert("'.addslashes(lang('%1 is NOT writable by you!',$path)).'"); Egw(window).close();'; |
||
| 2654 | } |
||
| 2655 | $err=null; |
||
| 2656 | $dupe_count = array(); |
||
| 2657 | $rememberServerID = $this->mail_bo->profileID; |
||
| 2658 | |||
| 2659 | /** |
||
| 2660 | * Extract all parameteres from the given id |
||
| 2661 | * @param int $id message id ('::' delimited mailbox::uid::part-id::is_winmail::name) |
||
| 2662 | * |
||
| 2663 | * @return array an array of parameters |
||
| 2664 | */ |
||
| 2665 | $getParams = function ($id) { |
||
| 2666 | list($app,$user,$serverID,$mailbox,$uid,$part,$is_winmail,$name) = explode('::',$id,8); |
||
| 2667 | $lId = implode('::',array($app,$user,$serverID,$mailbox,$uid)); |
||
| 2668 | $hA = mail_ui::splitRowID($lId); |
||
| 2669 | return array( |
||
| 2670 | 'is_winmail' => $is_winmail == "null" || !$is_winmail?false:$is_winmail, |
||
| 2671 | 'user' => $user, |
||
| 2672 | 'name' => $name, |
||
| 2673 | 'part' => $part, |
||
| 2674 | 'uid' => $hA['msgUID'], |
||
| 2675 | 'mailbox' => $hA['folder'], |
||
| 2676 | 'icServer' => $hA['profileID'] |
||
| 2677 | ); |
||
| 2678 | }; |
||
| 2679 | |||
| 2680 | //Examine the first attachment to see if attachment |
||
| 2681 | //is winmail.dat embedded attachments. |
||
| 2682 | $isMultipleDownload=is_array($ids); |
||
| 2683 | $p = $getParams((is_array($ids)?$ids[0]:$ids)); |
||
| 2684 | if ($p['is_winmail']) |
||
| 2685 | { |
||
| 2686 | View Code Duplication | if ($p['icServer'] && $p['icServer'] != $this->mail_bo->profileID) |
|
| 2687 | { |
||
| 2688 | $this->changeProfile($p['icServer']); |
||
| 2689 | } |
||
| 2690 | $this->mail_bo->reopen($p['mailbox']); |
||
| 2691 | // Retrive all embedded attachments at once |
||
| 2692 | // avoids to fetch heavy winmail.dat content |
||
| 2693 | // for each file. |
||
| 2694 | $attachments = $this->mail_bo->getTnefAttachments($p['uid'],$p['part']); |
||
| 2695 | } |
||
| 2696 | |||
| 2697 | foreach((array)$ids as $id) |
||
| 2698 | { |
||
| 2699 | $params = $getParams($id); |
||
| 2700 | // when downloading a single file, name is not set |
||
| 2701 | if (!$params['name']&&isset($_GET['name'])&&!$isMultipleDownload) $params['name'] = $_GET['name']; |
||
| 2702 | View Code Duplication | if ($params['icServer'] && $params['icServer'] != $this->mail_bo->profileID) |
|
| 2703 | { |
||
| 2704 | //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); |
||
| 2705 | $this->changeProfile($params['icServer']); |
||
| 2706 | } |
||
| 2707 | //error_log(__METHOD__.__LINE__.array2string($hA)); |
||
| 2708 | $this->mail_bo->reopen($params['mailbox']); |
||
| 2709 | if ($params['is_winmail']) |
||
| 2710 | { |
||
| 2711 | // Try to find the right content for file id |
||
| 2712 | foreach ($attachments as $key => $val) |
||
| 2713 | { |
||
| 2714 | if ($key == $params['is_winmail']) $attachment = $val; |
||
| 2715 | } |
||
| 2716 | } |
||
| 2717 | else |
||
| 2718 | { |
||
| 2719 | $attachment = $this->mail_bo->getAttachment($params['uid'],$params['part'],$params['is_winmail'],false); |
||
| 2720 | } |
||
| 2721 | |||
| 2722 | $file = $params['name']; |
||
| 2723 | // when $isMultipleDownload the path holds no filename |
||
| 2724 | while(Vfs::file_exists($path.($file && $isMultipleDownload ? '/'.$file : ''))) |
||
| 2725 | { |
||
| 2726 | $dupe_count[$params['name']]++; |
||
| 2727 | $file = pathinfo($params['name'], PATHINFO_FILENAME) . |
||
| 2728 | ' ('.($dupe_count[$params['name']] + 1).')' . '.' . |
||
| 2729 | pathinfo($params['name'], PATHINFO_EXTENSION); |
||
| 2730 | } |
||
| 2731 | $params['name'] = $file; |
||
| 2732 | //error_log(__METHOD__.__LINE__.array2string($attachment)); |
||
| 2733 | // when $isMultipleDownload the path holds no filename |
||
| 2734 | if (!($fp = Vfs::fopen($file=$path.($params['name'] && $isMultipleDownload ? '/'.$params['name'] : ''),'wb')) || |
||
| 2735 | !fwrite($fp,$attachment['attachment'])) |
||
| 2736 | { |
||
| 2737 | $err .= lang('Error saving %1!',$file); |
||
| 2738 | } |
||
| 2739 | if ($fp) |
||
| 2740 | { |
||
| 2741 | fclose($fp); |
||
| 2742 | } |
||
| 2743 | } |
||
| 2744 | $this->mail_bo->closeConnection(); |
||
| 2745 | if ($rememberServerID != $this->mail_bo->profileID) |
||
| 2746 | { |
||
| 2747 | //error_log(__METHOD__.__LINE__.' change Profile back to where we came from ->'.$rememberServerID); |
||
| 2748 | $this->changeProfile($rememberServerID); |
||
| 2749 | } |
||
| 2750 | Framework::window_close(($err?$err:null)); |
||
| 2751 | } |
||
| 2752 | |||
| 2753 | /** |
||
| 2754 | * Zip all attachments and send to user |
||
| 2755 | * @param string $message_id = null |
||
| 2756 | */ |
||
| 2757 | function download_zip($message_id=null) |
||
| 2758 | { |
||
| 2759 | //error_log(__METHOD__.__LINE__.array2string($_GET)); |
||
| 2760 | // First, get all attachment IDs |
||
| 2761 | if(isset($_GET['id'])) $message_id = $_GET['id']; |
||
| 2762 | //error_log(__METHOD__.__LINE__.$message_id); |
||
| 2763 | $rememberServerID = $this->mail_bo->profileID; |
||
| 2764 | if(!is_numeric($message_id)) |
||
| 2765 | { |
||
| 2766 | $hA = self::splitRowID($message_id); |
||
| 2767 | $message_id = $hA['msgUID']; |
||
| 2768 | $mailbox = $hA['folder']; |
||
| 2769 | $icServerID = $hA['profileID']; |
||
| 2770 | if ($icServerID && $icServerID != $this->mail_bo->profileID) |
||
| 2771 | { |
||
| 2772 | //error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID); |
||
| 2773 | $this->changeProfile($icServerID); |
||
| 2774 | } |
||
| 2775 | } |
||
| 2776 | else |
||
| 2777 | { |
||
| 2778 | $mailbox = $this->mail_bo->sessionData['mailbox']; |
||
| 2779 | } |
||
| 2780 | // always fetch all, even inline (images) |
||
| 2781 | $fetchEmbeddedImages = true; |
||
| 2782 | $attachments = $this->mail_bo->getMessageAttachments($message_id,null, null, $fetchEmbeddedImages, true,true,$mailbox); |
||
| 2783 | // put them in VFS so they can be zipped |
||
| 2784 | $header = $this->mail_bo->getMessageHeader($message_id,'',true,false,$mailbox); |
||
| 2785 | //get_home_dir may fetch the users startfolder if set; if not writeable, action will fail. TODO: use temp_dir |
||
| 2786 | $homedir = '/home/'.$GLOBALS['egw_info']['user']['account_lid']; |
||
| 2787 | $temp_path = $homedir/*Vfs::get_home_dir()*/ . "/.mail_$message_id"; |
||
| 2788 | if(Vfs::is_dir($temp_path)) Vfs::remove ($temp_path); |
||
| 2789 | |||
| 2790 | // Add subject to path, so it gets used as the file name |
||
| 2791 | $path = $temp_path . '/' . ($header['SUBJECT'] ? Vfs::encodePathComponent($header['SUBJECT']) : lang('mail')) .'/'; |
||
| 2792 | if(!Vfs::mkdir($path, 0700, true)) |
||
| 2793 | { |
||
| 2794 | Framework::message("Unable to open temp directory $path",'error'); |
||
| 2795 | return; |
||
| 2796 | } |
||
| 2797 | |||
| 2798 | $file_list = array(); |
||
| 2799 | $dupe_count = array(); |
||
| 2800 | $this->mail_bo->reopen($mailbox); |
||
| 2801 | if ($attachments[0]['is_winmail'] && $attachments[0]['is_winmail']!='null') |
||
| 2802 | { |
||
| 2803 | $tnefAttachments = $this->mail_bo->getTnefAttachments($message_id, $attachments[0]['partID'],true); |
||
| 2804 | } |
||
| 2805 | foreach($attachments as $file) |
||
| 2806 | { |
||
| 2807 | if ($file['is_winmail']) |
||
| 2808 | { |
||
| 2809 | // Try to find the right content for file id |
||
| 2810 | foreach ($tnefAttachments as $key => $val) |
||
| 2811 | { |
||
| 2812 | error_log(__METHOD__.' winmail = '.$key); |
||
| 2813 | if ($key == $file['is_winmail']) $attachment = $val; |
||
| 2814 | } |
||
| 2815 | } |
||
| 2816 | else |
||
| 2817 | { |
||
| 2818 | $attachment = $this->mail_bo->getAttachment($message_id,$file['partID'],$file['is_winmail'],false,true); |
||
| 2819 | } |
||
| 2820 | $success=true; |
||
| 2821 | if (empty($file['filename'])) $file['filename'] = $file['name']; |
||
| 2822 | if(in_array($path.$file['filename'], $file_list)) |
||
| 2823 | { |
||
| 2824 | $dupe_count[$path.$file['filename']]++; |
||
| 2825 | $file['filename'] = pathinfo($file['filename'], PATHINFO_FILENAME) . |
||
| 2826 | ' ('.($dupe_count[$path.$file['filename']] + 1).')' . '.' . |
||
| 2827 | pathinfo($file['filename'], PATHINFO_EXTENSION); |
||
| 2828 | } |
||
| 2829 | if (!($fp = Vfs::fopen($path.$file['filename'],'wb')) || |
||
| 2830 | !(!fseek($attachment['attachment'], 0, SEEK_SET) && stream_copy_to_stream($attachment['attachment'], $fp))) |
||
| 2831 | { |
||
| 2832 | $success=false; |
||
| 2833 | Framework::message("Unable to zip {$file['filename']}",'error'); |
||
| 2834 | } |
||
| 2835 | if ($success) $file_list[] = $path.$file['filename']; |
||
| 2836 | if ($fp) fclose($fp); |
||
| 2837 | } |
||
| 2838 | $this->mail_bo->closeConnection(); |
||
| 2839 | if ($rememberServerID != $this->mail_bo->profileID) |
||
| 2840 | { |
||
| 2841 | //error_log(__METHOD__.__LINE__.' change Profile back to where we came from ->'.$rememberServerID); |
||
| 2842 | $this->changeProfile($rememberServerID); |
||
| 2843 | } |
||
| 2844 | |||
| 2845 | // Zip it up |
||
| 2846 | Vfs::download_zip($file_list); |
||
| 2847 | |||
| 2848 | // Clean up |
||
| 2849 | Vfs::remove($temp_path); |
||
| 2850 | |||
| 2851 | exit(); |
||
| 2852 | } |
||
| 2853 | |||
| 2854 | function get_load_email_data($uid, $partID, $mailbox,$htmlOptions=null) |
||
| 2855 | { |
||
| 2856 | // seems to be needed, as if we open a mail from notification popup that is |
||
| 2857 | // located in a different folder, we experience: could not parse message |
||
| 2858 | $this->mail_bo->reopen($mailbox); |
||
| 2859 | $this->mailbox = $mailbox; |
||
| 2860 | $this->uid = $uid; |
||
| 2861 | $this->partID = $partID; |
||
| 2862 | $bufferHtmlOptions = $this->mail_bo->htmlOptions; |
||
| 2863 | if (empty($htmlOptions)) $htmlOptions = $this->mail_bo->htmlOptions; |
||
| 2864 | // fetching structure now, to supply it to getMessageBody and getMessageAttachment, so it does not get fetched twice |
||
| 2865 | $structure = $this->mail_bo->getStructure($uid, $partID, $mailbox, false); |
||
| 2866 | $calendar_part = null; |
||
| 2867 | $bodyParts = $this->mail_bo->getMessageBody($uid, ($htmlOptions?$htmlOptions:''), $partID, $structure, false, $mailbox, $calendar_part); |
||
| 2868 | |||
| 2869 | // for meeting requests (multipart alternative with text/calendar part) let calendar render it |
||
| 2870 | if ($calendar_part && isset($GLOBALS['egw_info']['user']['apps']['calendar'])) |
||
| 2871 | { |
||
| 2872 | $charset = $calendar_part->getContentTypeParameter('charset'); |
||
| 2873 | $this->mail_bo->fetchPartContents($uid, $calendar_part); |
||
| 2874 | Api\Cache::setSession('calendar', 'ical', array( |
||
| 2875 | 'charset' => $charset ? $charset : 'utf-8', |
||
| 2876 | 'attachment' => $calendar_part->getContents(), |
||
| 2877 | 'method' => $calendar_part->getContentTypeParameter('method'), |
||
| 2878 | )); |
||
| 2879 | $this->mail_bo->htmlOptions = $bufferHtmlOptions; |
||
| 2880 | Api\Translation::add_app('calendar'); |
||
| 2881 | return ExecMethod('calendar.calendar_uiforms.meeting', |
||
| 2882 | array('event'=>null,'msg'=>'','useSession'=>true) |
||
| 2883 | ); |
||
| 2884 | } |
||
| 2885 | // Compose the content of the frame |
||
| 2886 | $frameHtml = |
||
| 2887 | $this->get_email_header($this->mail_bo->getStyles($bodyParts)). |
||
| 2888 | $this->showBody($this->getdisplayableBody($bodyParts,true,false), false); |
||
| 2889 | //IE10 eats away linebreaks preceeded by a whitespace in PRE sections |
||
| 2890 | $frameHtml = str_replace(" \r\n","\r\n",$frameHtml); |
||
| 2891 | $this->mail_bo->htmlOptions = $bufferHtmlOptions; |
||
| 2892 | |||
| 2893 | return $frameHtml; |
||
| 2894 | } |
||
| 2895 | |||
| 2896 | static function get_email_header($additionalStyle='') |
||
| 2911 | |||
| 2912 | function showBody(&$body, $print=true,$fullPageTags=true) |
||
| 2925 | |||
| 2926 | function &getdisplayableBody($_bodyParts,$modifyURI=true,$useTidy = true) |
||
| 2927 | { |
||
| 2928 | $bodyParts = $_bodyParts; |
||
| 2929 | |||
| 2930 | $nonDisplayAbleCharacters = array('[\016]','[\017]', |
||
| 2931 | '[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]', |
||
| 2932 | '[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]'); |
||
| 2933 | |||
| 2934 | $body = ''; |
||
| 2935 | |||
| 2936 | //error_log(__METHOD__.array2string($bodyParts)); //exit; |
||
| 2937 | if (empty($bodyParts)) return ""; |
||
| 2938 | foreach((array)$bodyParts as $singleBodyPart) { |
||
| 2939 | if (!isset($singleBodyPart['body'])) { |
||
| 2940 | $singleBodyPart['body'] = $this->getdisplayableBody($singleBodyPart,$modifyURI,$useTidy); |
||
| 2941 | $body .= $singleBodyPart['body']; |
||
| 2942 | continue; |
||
| 2943 | } |
||
| 2944 | $bodyPartIsSet = strlen(trim($singleBodyPart['body'])); |
||
| 2945 | if (!$bodyPartIsSet) |
||
| 2946 | { |
||
| 2947 | $body .= ''; |
||
| 2948 | continue; |
||
| 2949 | } |
||
| 2950 | if(!empty($body)) { |
||
| 2951 | $body .= '<hr style="border:dotted 1px silver;">'; |
||
| 2952 | } |
||
| 3123 | |||
| 3124 | /** |
||
| 3125 | * Resolve inline images from CID to proper url |
||
| 3126 | * |
||
| 3127 | * @param string $_body message content |
||
| 3128 | * @param string $_mailbox mail folder |
||
| 3129 | * @param string $_uid uid |
||
| 3130 | * @param string $_partID part id |
||
| 3131 | * @param string $_messageType = 'html', message type is either html or plain |
||
| 3132 | * @return string message body including all CID images replaced |
||
| 3133 | */ |
||
| 3134 | public static function resolve_inline_images ($_body,$_mailbox, $_uid, $_partID, $_messageType = 'html') |
||
| 3149 | |||
| 3150 | /** |
||
| 3151 | * Replace CID with proper type of content understandable by browser |
||
| 3152 | * |
||
| 3153 | * @param type $_body content of message |
||
| 3154 | * @param type $_mailbox mail box |
||
| 3155 | * @param type $_uid uid |
||
| 3156 | * @param type $_partID part id |
||
| 3157 | * @param type $_type = 'src' type of inline image that needs to be resolved and replaced |
||
| 3158 | * - types: {plain|src|url|background} |
||
| 3159 | * @return string returns body content including all CID replacements |
||
| 3160 | */ |
||
| 3161 | public static function resolve_inline_image_byType ($_body,$_mailbox, $_uid, $_partID, $_type ='src') |
||
| 3265 | |||
| 3266 | /** |
||
| 3267 | * importMessage |
||
| 3268 | * @param array $content = null an array of content |
||
| 3269 | */ |
||
| 3270 | function importMessage($content=null) |
||
| 3334 | |||
| 3335 | /** |
||
| 3336 | * importMessageToFolder |
||
| 3337 | * |
||
| 3338 | * @param array $_formData Array with information of name, type, file and size |
||
| 3339 | * @param string $_folder (passed by reference) will set the folder used. must be set with a folder, but will hold modifications if |
||
| 3340 | * folder is modified |
||
| 3341 | * @param string $importID ID for the imported message, used by attachments to identify them unambiguously |
||
| 3342 | * @return mixed $messageUID or exception |
||
| 3343 | */ |
||
| 3344 | function importMessageToFolder($_formData,&$_folder,$importID='') |
||
| 3412 | |||
| 3413 | /** |
||
| 3414 | * importMessageFromVFS2DraftAndEdit |
||
| 3415 | * |
||
| 3416 | * @param array $formData Array with information of name, type, file and size; file is required, |
||
| 3417 | * name, type and size may be set here to meet the requirements |
||
| 3418 | * Example: $formData['name'] = 'a_email.eml'; |
||
| 3419 | * $formData['type'] = 'message/rfc822'; |
||
| 3420 | * $formData['file'] = 'vfs://default/home/leithoff/a_email.eml'; |
||
| 3421 | * $formData['size'] = 2136; |
||
| 3422 | * @return void |
||
| 3423 | */ |
||
| 3424 | function importMessageFromVFS2DraftAndEdit($formData='') |
||
| 3428 | |||
| 3429 | /** |
||
| 3430 | * importMessageFromVFS2DraftAndDisplay |
||
| 3431 | * |
||
| 3432 | * @param array $formData Array with information of name, type, file and size; file is required, |
||
| 3433 | * name, type and size may be set here to meet the requirements |
||
| 3434 | * Example: $formData['name'] = 'a_email.eml'; |
||
| 3435 | * $formData['type'] = 'message/rfc822'; |
||
| 3436 | * $formData['file'] = 'vfs://default/home/leithoff/a_email.eml'; |
||
| 3437 | * $formData['size'] = 2136; |
||
| 3438 | * @param string $mode mode to open ImportedMessage display and edit are supported |
||
| 3439 | * @return void |
||
| 3440 | */ |
||
| 3441 | function importMessageFromVFS2DraftAndDisplay($formData='',$mode='display') |
||
| 3497 | |||
| 3498 | /** |
||
| 3499 | * loadEmailBody |
||
| 3500 | * |
||
| 3501 | * @param string _messageID UID |
||
| 3502 | * |
||
| 3503 | * @return xajax response |
||
| 3504 | */ |
||
| 3505 | function loadEmailBody($_messageID=null,$_partID=null,$_htmloptions=null) |
||
| 3531 | |||
| 3532 | /** |
||
| 3533 | * ajax_setFolderStatus - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 3534 | * gets the counters and sets the text of a treenode if needed (unread Messages found) |
||
| 3535 | * @param array $_folder folders to refresh its unseen message counters |
||
| 3536 | * @return nothing |
||
| 3537 | */ |
||
| 3538 | function ajax_setFolderStatus($_folder) |
||
| 3584 | |||
| 3585 | /** |
||
| 3586 | * ajax_addFolder - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 3587 | * @param string $_parentFolderName folder to add a folder to |
||
| 3588 | * @param string $_newName new foldername |
||
| 3589 | * @return nothing |
||
| 3590 | */ |
||
| 3591 | function ajax_addFolder($_parentFolderName, $_newName) |
||
| 3694 | |||
| 3695 | /** |
||
| 3696 | * ajax_renameFolder - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 3697 | * @param string $_folderName folder to rename and refresh |
||
| 3698 | * @param string $_newName new foldername |
||
| 3699 | * @return nothing |
||
| 3700 | */ |
||
| 3701 | function ajax_renameFolder($_folderName, $_newName) |
||
| 3834 | |||
| 3835 | /** |
||
| 3836 | * reload node |
||
| 3837 | * |
||
| 3838 | * @param string _folderName folder to reload |
||
| 3839 | * @param boolean $_subscribedOnly = true |
||
| 3840 | * @return void |
||
| 3841 | */ |
||
| 3842 | function ajax_reloadNode($_folderName,$_subscribedOnly=true) |
||
| 3889 | |||
| 3890 | /** |
||
| 3891 | * ResolveWinmail fetches the encoded attachments |
||
| 3892 | * from winmail.dat and will response expected structure back |
||
| 3893 | * to client in order to display them. |
||
| 3894 | * |
||
| 3895 | * Note: this ajax function should only be called via |
||
| 3896 | * nm mail selection as it does not support profile change |
||
| 3897 | * and uses the current available ic_server connection. |
||
| 3898 | * |
||
| 3899 | * @param type $_rowid row id from nm |
||
| 3900 | * |
||
| 3901 | */ |
||
| 3902 | function ajax_resolveWinmail ($_rowid) |
||
| 3921 | |||
| 3922 | /** |
||
| 3923 | * move folder |
||
| 3924 | * |
||
| 3925 | * @param string _folderName folder to vove |
||
| 3926 | * @param string _target target folder |
||
| 3927 | * |
||
| 3928 | * @return void |
||
| 3929 | */ |
||
| 3930 | function ajax_MoveFolder($_folderName, $_target) |
||
| 4057 | |||
| 4058 | /** |
||
| 4059 | * ajax_deleteFolder - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 4060 | * @param string $_folderName folder to delete |
||
| 4061 | * @param boolean $_return = false wheter return the success value (true) or send response to client (false) |
||
| 4062 | * @return nothing |
||
| 4063 | */ |
||
| 4064 | function ajax_deleteFolder($_folderName, $_return = false) |
||
| 4155 | |||
| 4156 | /** |
||
| 4157 | * empty changeProfile - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 4158 | * |
||
| 4159 | * Made static to NOT call __construct, as it would connect to old server, before going to new one |
||
| 4160 | * |
||
| 4161 | * @param int $icServerID New profile / server ID |
||
| 4162 | * @param bool $getFolders The client needs the folders for the profile |
||
| 4163 | * @return nothing |
||
| 4164 | */ |
||
| 4165 | public static function ajax_changeProfile($icServerID, $getFolders = true, $exec_id=null) |
||
| 4208 | |||
| 4209 | /** |
||
| 4210 | * ajax_refreshVacationNotice - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 4211 | * Note: only the activeProfile VacationNotice is refreshed |
||
| 4212 | * @param int $icServerID profileId / server ID to work on; may be empty -> then activeProfile is used |
||
| 4213 | * if other than active profile; nothing is done! |
||
| 4214 | * @return nothing |
||
| 4215 | */ |
||
| 4216 | public static function ajax_refreshVacationNotice($icServerID=null) |
||
| 4257 | |||
| 4258 | /** |
||
| 4259 | * ajax_refreshFilters - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 4260 | * Note: only the activeProfile Filters are refreshed |
||
| 4261 | * @param int $icServerID profileId / server ID to work on; may be empty -> then activeProfile is used |
||
| 4262 | * if other than active profile; nothing is done! |
||
| 4263 | * @return nothing |
||
| 4264 | */ |
||
| 4265 | function ajax_refreshFilters($icServerID=null) |
||
| 4304 | |||
| 4305 | /** |
||
| 4306 | * This function asks quota from IMAP server and makes the |
||
| 4307 | * result as JSON response to send it to mail_sendQuotaDisplay |
||
| 4308 | * function in client side. |
||
| 4309 | * |
||
| 4310 | * @param string $icServerID = null |
||
| 4311 | * |
||
| 4312 | */ |
||
| 4313 | function ajax_refreshQuotaDisplay($icServerID=null) |
||
| 4363 | |||
| 4364 | /** |
||
| 4365 | * Empty spam/junk folder |
||
| 4366 | * |
||
| 4367 | * @param string $icServerID id of the server to empty its junkFolder |
||
| 4368 | * @param string $selectedFolder seleted(active) folder by nm filter |
||
| 4369 | * @return nothing |
||
| 4370 | */ |
||
| 4371 | View Code Duplication | function ajax_emptySpam($icServerID, $selectedFolder) |
|
| 4413 | |||
| 4414 | /** |
||
| 4415 | * Empty trash folder |
||
| 4416 | * |
||
| 4417 | * @param string $icServerID id of the server to empty its trashFolder |
||
| 4418 | * @param string $selectedFolder seleted(active) folder by nm filter |
||
| 4419 | * @return nothing |
||
| 4420 | */ |
||
| 4421 | View Code Duplication | function ajax_emptyTrash($icServerID, $selectedFolder) |
|
| 4463 | |||
| 4464 | /** |
||
| 4465 | * compress folder - its called via json, so the function must start with ajax (or the class-name must contain ajax) |
||
| 4466 | * fetches the current folder from session and compresses it |
||
| 4467 | * @param string $_folderName id of the folder to compress |
||
| 4468 | * @return nothing |
||
| 4469 | */ |
||
| 4470 | function ajax_compressFolder($_folderName) |
||
| 4500 | |||
| 4501 | /** |
||
| 4502 | * sendMDN, ... |
||
| 4503 | * |
||
| 4504 | * @param array _messageList list of UID's |
||
| 4505 | * |
||
| 4506 | * @return nothing |
||
| 4507 | */ |
||
| 4508 | function ajax_sendMDN($_messageList) |
||
| 4515 | |||
| 4516 | /** |
||
| 4517 | * flag messages as read, unread, flagged, ... |
||
| 4518 | * |
||
| 4519 | * @param string _flag name of the flag |
||
| 4520 | * @param array _messageList list of UID's |
||
| 4521 | * @param bool _sendJsonResponse tell fuction to send the JsonResponse |
||
| 4522 | * |
||
| 4523 | * @return xajax response |
||
| 4524 | */ |
||
| 4525 | function ajax_flagMessages($_flag, $_messageList, $_sendJsonResponse=true) |
||
| 4713 | |||
| 4714 | /** |
||
| 4715 | * delete messages |
||
| 4716 | * |
||
| 4717 | * @param array _messageList list of UID's |
||
| 4718 | * @param string _forceDeleteMethod - method of deletion to be enforced |
||
| 4719 | * @return xajax response |
||
| 4720 | */ |
||
| 4721 | function ajax_deleteMessages($_messageList,$_forceDeleteMethod=null) |
||
| 4834 | |||
| 4835 | /** |
||
| 4836 | * copy messages |
||
| 4837 | * |
||
| 4838 | * @param array _folderName target folder |
||
| 4839 | * @param array _messageList list of UID's |
||
| 4840 | * @param string _copyOrMove method to use copy or move allowed |
||
| 4841 | * @param string _move2ArchiveMarker marker to indicate if a move 2 archive was triggered |
||
| 4842 | * |
||
| 4843 | * @return xajax response |
||
| 4844 | */ |
||
| 4845 | function ajax_copyMessages($_folderName, $_messageList, $_copyOrMove='copy', $_move2ArchiveMarker='_') |
||
| 5038 | |||
| 5039 | /** |
||
| 5040 | * Autoloading function to load branches of tree node |
||
| 5041 | * of management folder tree |
||
| 5042 | * |
||
| 5043 | * @param type $_id |
||
| 5044 | */ |
||
| 5045 | function ajax_folderMgmtTree_autoloading ($_id = null) |
||
| 5051 | |||
| 5052 | /** |
||
| 5053 | * Main function to handle folder management dialog |
||
| 5054 | * |
||
| 5055 | * @param array $content content of dialog |
||
| 5056 | */ |
||
| 5057 | function folderManagement (array $content = null) |
||
| 5075 | |||
| 5076 | /** |
||
| 5077 | * Function to delete folder for management longTask dialog |
||
| 5078 | * it sends successfully deleted folder as response to be |
||
| 5079 | * used in long task response handler. |
||
| 5080 | * |
||
| 5081 | * @param type $_folderName |
||
| 5082 | */ |
||
| 5083 | function ajax_folderMgmt_delete ($_folderName) |
||
| 5101 | } |
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: