Mercurial > hg > rc1
comparison plugins/thunderbird_labels/thunderbird_labels.php @ 24:4869fae20b88
do better at flag deletion, unthreaded dates sort working, preparing for threaded
| author | Charlie Root |
|---|---|
| date | Wed, 17 Jan 2018 17:40:51 -0500 |
| parents | 5a851d965bc1 |
| children | 4b2bc456ce42 |
comparison
equal
deleted
inserted
replaced
| 23:5a851d965bc1 | 24:4869fae20b88 |
|---|---|
| 330 return $p; | 330 return $p; |
| 331 } | 331 } |
| 332 | 332 |
| 333 public function read_flags($args) | 333 public function read_flags($args) |
| 334 { | 334 { |
| 335 rcube::write_log($this->name, "read: ".$_SESSION['sort_col']); | |
| 336 // add color information for all messages | 335 // add color information for all messages |
| 337 // dont loop over all messages if we dont have any highlights or no msgs | 336 // dont loop over all messages if we dont have any highlights or no msgs |
| 338 if (!isset($args['messages']) or !is_array($args['messages'])) { | 337 if (!isset($args['messages']) or !is_array($args['messages'])) { |
| 339 return $args; | 338 return $args; |
| 340 } | 339 } |
| 341 // loop over all messages and add $LabelX info to the extra_flags | 340 // loop over all messages and add $LabelX info to the extra_flags |
| 341 $mbox = $this->rc->output->get_env('mailbox') ?: $this->rc->storage->get_folder(); | |
| 342 rcube::write_log($this->name, "mbox: $mbox"); | |
| 342 foreach($args['messages'] as $message) | 343 foreach($args['messages'] as $message) |
| 343 { | 344 { |
| 344 #rcube::write_log($this->name, print_r($message->flags, true)); | |
| 345 $message->list_flags['extra_flags']['tb_labels'] = array(); # always set extra_flags, needed for javascript later! | 345 $message->list_flags['extra_flags']['tb_labels'] = array(); # always set extra_flags, needed for javascript later! |
| 346 $message->list_flags['extra_flags']['tb_parms'] = array(); | 346 $message->list_flags['extra_flags']['tb_lparms'] = array(); |
| 347 $keyPos = array_search($_SESSION['sort_col'],$this->rc->config->get('tb_label_parm_labels')); | 347 $keyPos = array_search($_SESSION['sort_col'],$this->rc->config->get('tb_label_parm_labels')); |
| 348 rcube::write_log($this->name,"sort? $keyPos ".$_SESSION['sort_order']." ".print_r($this->rc->config->get('tb_label_parm_labels'),true)); | 348 rcube::write_log($this->name,"sort? $keyPos ".$_SESSION['sort_order']." ".print_r($this->rc->config->get('tb_label_parm_labels'),true)); |
| 349 if (is_array($message->flags)) | 349 if (is_array($message->flags)) |
| 350 foreach ($message->flags as $flagname => $flagvalue) | 350 foreach ($message->flags as $flagname => $flagvalue) |
| 351 { | 351 { |
| 360 $pn=(int)substr($flag_no,0,$ppos); | 360 $pn=(int)substr($flag_no,0,$ppos); |
| 361 $pv=substr($flag_no,$ppos+1); | 361 $pv=substr($flag_no,$ppos+1); |
| 362 $message->list_flags['extra_flags']['tb_lparms'][]=array( | 362 $message->list_flags['extra_flags']['tb_lparms'][]=array( |
| 363 'number' => $pn, | 363 'number' => $pn, |
| 364 'parm' => $pv); | 364 'parm' => $pv); |
| 365 if ($keyPos) { | 365 if ($keyPos && $message->depth==0) { |
| 366 $message->sortKey=array_map('intval',preg_split('/[/-]/',$pv)); | 366 $message->sortKey=array_map('intval',preg_split('#[/-]#',$pv)); |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 else { | 369 else { |
| 370 $message->list_flags['extra_flags']['tb_labels'][] = (int)$flag_no; | 370 $message->list_flags['extra_flags']['tb_labels'][] = (int)$flag_no; |
| 371 } | 371 } |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 if ($keyPos) { | 375 if ($keyPos) { |
| 376 $rev = $_SESSION['sort_order']=='DESC'; | 376 $rev = $_SESSION['sort_order']=='DESC'; |
| 377 usort($args['messages'], | 377 $datesSort = |
| 378 function($a, $b) use ($rev) { | 378 function($a, $b) use ($rev) { |
| 379 if ($ak=$a->sortKey) { | 379 if ($ak=$a->sortKey) { |
| 380 if ($bk=$b->sortKey) { | 380 if ($bk=$b->sortKey) { |
| 381 // each key is sd sm ed em | 381 // each key is sd sm ed em |
| 382 if ($ak[1]<$bk[1]) return $rev?1:-1; | 382 if ($ak[1]<$bk[1]) return $rev?1:-1; |
| 383 if ($ak[1]>$bk[1]) return $rev?-1:1; | 383 if ($ak[1]>$bk[1]) return $rev?-1:1; |
| 384 // start month is the same | 384 // start month is the same |
| 385 if ($ak[0]<$bk[0]) return $rev?1:-1; | 385 if ($ak[0]<$bk[0]) return $rev?1:-1; |
| 386 if ($ak[0]>$bk[0]) return $rev?-1:1; | 386 if ($ak[0]>$bk[0]) return $rev?-1:1; |
| 387 // start date is the same | 387 // start date is the same |
| 388 if ($ak[3]<$bk[3]) return $rev?1:-1; | 388 if ($ak[3]<$bk[3]) return $rev?1:-1; |
| 389 if ($ak[3]>$bk[3]) return $rev?-1:1; | 389 if ($ak[3]>$bk[3]) return $rev?-1:1; |
| 390 // end month is the same | 390 // end month is the same |
| 391 if ($ak[2]<$bk[2]) return $rev?1:-1; | 391 if ($ak[2]<$bk[2]) return $rev?1:-1; |
| 392 if ($ak[2]>$bk[2]) return $rev?-1:1; | 392 if ($ak[2]>$bk[2]) return $rev?-1:1; |
| 393 // both dates are the same | 393 // both dates are the same |
| 394 return 0; | |
| 395 } | |
| 396 else { | |
| 397 return $rev?1:-1; | |
| 398 } | |
| 399 } | |
| 400 else if ($b->sortKey) { | |
| 401 return $rev?-1:1; | |
| 402 } | |
| 403 else { | |
| 394 return 0; | 404 return 0; |
| 395 } | 405 } |
| 396 else { | 406 }; |
| 397 return $rev?1:-1; | 407 if ($this->rc->config->get('message_threading')[$mbox]) { |
| 398 } | 408 // The threading information is contained in three fields: |
| 399 } | 409 // depth, parent_uid and uid |
| 400 else if ($b->sortKey) { | 410 // I _think_ if you gave every depth0 message its dates as key |
| 401 return $rev?-1:1; | 411 // every depth>0 its date as key |
| 402 } | 412 // Then first sort all the depth0 messages into a new array |
| 403 else { | 413 // then iterate over them, pull all depth1 with shared parent and sort _them, |
| 404 return 0; | 414 // insert after parent |
| 405 } | 415 // repeat at depth 1, etc. |
| 406 }); | 416 } |
| 417 else { | |
| 418 usort($args['messages'],$datesSort); | |
| 419 } | |
| 407 } | 420 } |
| 408 return($args); | 421 return($args); |
| 409 } | 422 } |
| 410 | 423 |
| 411 // set flags in IMAP server | 424 // set flags in IMAP server |
| 430 if (!is_array($unflag_uids) | 443 if (!is_array($unflag_uids) |
| 431 || !is_array($flag_uids)) | 444 || !is_array($flag_uids)) |
| 432 return false; | 445 return false; |
| 433 | 446 |
| 434 $imap->set_flag($flag_uids, $toggle_label, $mbox); | 447 $imap->set_flag($flag_uids, $toggle_label, $mbox); |
| 435 $imap->set_flag($unflag_uids, "UN$toggle_label", $mbox); | 448 // belt and braces |
| 436 | 449 if (count($unflag_uids)>0) { |
| 450 $flaggedMsgs = $imap->list_flags($mbox,$unflag_uids); | |
| 451 rcube::write_log($this->name,'oldFlags: '.print_r($flaggedMsgs,true)); | |
| 452 $fullFlags=array(); | |
| 453 foreach ($flaggedMsgs as $uid => $flags) { | |
| 454 foreach ($flags as $flag => $x) { | |
| 455 $pos=strpos(strtolower($flag),$toggle_label); | |
| 456 rcube::write_log($this->name,"flag?: $flag $toggle_label $pos"); | |
| 457 if ($pos>-1 && $pos<2 && !in_array($flag,$fullFlags)) { | |
| 458 $fullFlags[]=$flag; | |
| 459 } | |
| 460 } | |
| 461 } | |
| 462 if (count($fullFlags)==0) { | |
| 463 rcube::write_log('errors',"no full flags for $toggle_label in ".print_r($flaggedMsgs,true)); | |
| 464 $imap->set_flag($unflag_uids, "UN$toggle_label", $mbox); | |
| 465 } | |
| 466 else { | |
| 467 foreach ($fullFlags as $flag) { | |
| 468 rcube::write_log($this->name,"UNsetting $flag in $mbox for ".join(',',$unflag_uids)); | |
| 469 $imap->set_flag($unflag_uids, "UN$flag", $mbox); | |
| 470 } | |
| 471 } | |
| 472 } | |
| 437 $this->api->output->send(); | 473 $this->api->output->send(); |
| 438 } | 474 } |
| 439 | 475 |
| 440 function tb_label_popup() | 476 function tb_label_popup() |
| 441 { | 477 { |
