1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Ajax_Application_Handler_Dynamic
24: extends Horde_Core_Ajax_Application_Handler
25: {
26: 27: 28: 29: 30:
31: protected $_readOnly = array(
32: 'html2Text', 'text2Html'
33: );
34:
35: 36: 37: 38: 39: 40: 41: 42: 43: 44:
45: public function createMailboxPrepare()
46: {
47: $mbox = IMP_Mailbox::formFrom($this->vars->mbox);
48: $ret = new stdClass;
49: $ret->result = true;
50:
51: if (!$mbox->access_creatembox) {
52: $GLOBALS['notification']->push(sprintf(_("You may not create child mailboxes in \"%s\"."), $mbox->display), 'horde.error');
53: $ret->result = false;
54: }
55:
56: return $ret;
57: }
58:
59: 60: 61: 62: 63: 64: 65: 66: 67: 68:
69: public function createMailbox()
70: {
71: global $injector, $notification;
72:
73: if (!isset($this->vars->mbox)) {
74: return false;
75: }
76:
77: $result = false;
78:
79: $parent = isset($this->vars->parent)
80: ? IMP_Mailbox::formFrom($this->vars->parent)
81: : IMP_Mailbox::get(IMP_Ftree::BASE_ELT);
82: $new_mbox = $parent->createMailboxName($this->vars->mbox);
83:
84: if ($new_mbox->exists) {
85: $notification->push(sprintf(_("Mailbox \"%s\" already exists."), $new_mbox->display), 'horde.warning');
86: } elseif ($new_mbox->create()) {
87: $result = true;
88:
89: if ($this->vars->create_poll) {
90: $injector->getInstance('IMP_Ftree')->poll->addPollList($new_mbox);
91: $this->_base->queue->poll($new_mbox);
92: }
93: }
94:
95: return $result;
96: }
97:
98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108:
109: public function deleteMailboxPrepare()
110: {
111: $mbox = IMP_Mailbox::formFrom($this->vars->mbox);
112: $ret = new stdClass;
113:
114: if ($mbox->access_deletembox) {
115: $ret->result = true;
116: return $ret;
117: }
118:
119: switch ($this->vars->type) {
120: case 'delete':
121: $GLOBALS['notification']->push(sprintf(_("You may not delete \"%s\"."), $mbox->display), 'horde.error');
122: break;
123:
124: case 'rename':
125: $GLOBALS['notification']->push(sprintf(_("You may not rename \"%s\"."), $mbox->display), 'horde.error');
126: break;
127: }
128:
129: $ret->result = false;
130: return $ret;
131: }
132:
133: 134: 135: 136: 137: 138: 139: 140: 141: 142:
143: public function deleteMailbox()
144: {
145: return ($this->vars->mbox && IMP_Mailbox::formFrom($this->vars->mbox)->delete(array(
146: 'subfolders' => !empty($this->vars->subfolders),
147: 'subfolders_only' => !empty($this->vars->container)
148: )));
149: }
150:
151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161:
162: public function renameMailbox()
163: {
164: if (!$this->vars->old_name || !$this->vars->new_name) {
165: return false;
166: }
167:
168: $old_name = IMP_Mailbox::formFrom($this->vars->old_name);
169: if (isset($this->vars->new_parent)) {
170: $parent = strlen($this->vars->new_parent)
171: ? IMP_Mailbox::formFrom($this->vars->new_parent)
172: : IMP_Mailbox::get(IMP_Ftree::BASE_ELT);
173: } else {
174: $parent = IMP_Mailbox::get($old_name->parent);
175: }
176:
177: if ($parent) {
178: $new_name = $parent->createMailboxName($this->vars->new_name);
179:
180: if (($old_name != $new_name) && $old_name->rename($new_name)) {
181: $this->_base->queue->setMailboxOpt('switch', $new_name->form_to);
182: return true;
183: }
184: }
185:
186: return false;
187: }
188:
189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199:
200: public function emptyMailboxPrepare()
201: {
202: $mbox = IMP_Mailbox::formFrom($this->vars->mbox);
203: $res = new stdClass;
204: $res->result = 0;
205:
206: if (!$mbox->access_empty) {
207: $GLOBALS['notification']->push(sprintf(_("The mailbox \"%s\" may not be emptied."), $mbox->display), 'horde.error');
208: } else {
209: $poll_info = $mbox->poll_info;
210: if (!($res->result = $poll_info->msgs)) {
211: $GLOBALS['notification']->push(sprintf(_("The mailbox \"%s\" is already empty."), $mbox->display), 'horde.message');
212: }
213: }
214:
215: return $res;
216: }
217:
218: 219: 220: 221: 222: 223: 224: 225:
226: public function emptyMailbox()
227: {
228: if (!$this->vars->mbox) {
229: return false;
230: }
231:
232: $mbox = IMP_Mailbox::formFrom($this->vars->mbox);
233:
234: $GLOBALS['injector']->getInstance('IMP_Message')->emptyMailbox(array($mbox));
235:
236: $this->_base->queue->poll($mbox);
237:
238: $vp = new IMP_Ajax_Application_Viewport($mbox);
239: $vp->data_reset = 1;
240: $vp->rowlist_reset = 1;
241: $this->_base->addTask('viewport', $vp);
242:
243: return true;
244: }
245:
246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256:
257: public function flagAll()
258: {
259: $flags = json_decode($this->vars->flags);
260: if (!$this->vars->mbox || empty($flags)) {
261: return false;
262: }
263:
264: $mbox = IMP_Mailbox::formFrom($this->vars->mbox);
265:
266: if (!$GLOBALS['injector']->getInstance('IMP_Message')->flagAllInMailbox($flags, array($mbox), $this->vars->add)) {
267: return false;
268: }
269:
270: $this->_base->queue->poll($mbox);
271:
272: return true;
273: }
274:
275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290:
291: public function listMailboxes()
292: {
293: global $injector, $prefs, $session;
294:
295: $ftree = $injector->getInstance('IMP_Ftree');
296: $iterator = new AppendIterator();
297:
298:
299: if ($this->vars->initial) {
300: $session->close();
301: $ftree->eltdiff->clear();
302:
303:
304: if ($ftree->unsubscribed_loaded && !$this->vars->reload) {
305: $ftree->init();
306: }
307: }
308:
309: if ($this->vars->reload) {
310: $ftree->init();
311: }
312:
313: $filter = new IMP_Ftree_IteratorFilter($ftree);
314: if ($this->vars->unsub) {
315: $ftree->loadUnsubscribed();
316: $filter->remove($filter::UNSUB);
317: }
318:
319: if (isset($this->vars->base)) {
320: $this->_base->queue->setMailboxOpt('base', $this->vars->base);
321: }
322:
323: if ($this->vars->all) {
324: $this->_base->queue->setMailboxOpt('all', 1);
325: $iterator->append($filter);
326: if ($this->vars->expall) {
327: $this->vars->action = 'expand';
328: $this->_base->callAction('toggleMailboxes');
329: }
330: } elseif ($this->vars->initial || $this->vars->reload) {
331: $special = new ArrayIterator();
332: $special->append($ftree['INBOX']);
333:
334: 335: 336:
337: $s_elts = array();
338: foreach (IMP_Mailbox::getSpecialMailboxesSort() as $val) {
339: if (isset($ftree[$val])) {
340: $special->append($val);
341: $s_elts[] = $ftree[$val];
342: }
343: }
344: $iterator->append($special);
345:
346: 347: 348:
349: $filter2 = clone $filter;
350: $filter2->add(array($filter2::CONTAINERS, $filter2::SPECIALMBOXES));
351: $no_children = array();
352:
353: foreach (array_unique($s_elts) as $val) {
354: while (($val = $val->parent) && !$val->base_elt) {
355: $filter2->iterator = new IMP_Ftree_Iterator($val);
356: foreach ($filter2 as $val) {
357: 358:
359: break 2;
360: }
361: $no_children[] = strval($val);
362: }
363: }
364:
365: if (!empty($no_children)) {
366: $this->_base->queue->ftreeCallback = function($id, $ob) use ($no_children) {
367: if (in_array($id, $no_children)) {
368: unset($ob->ch);
369: }
370: };
371: }
372:
373:
374: $no_mbox = false;
375:
376: switch ($prefs->getValue('nav_expanded')) {
377: case IMP_Ftree_Prefs_Expanded::NO:
378: $filter->add($filter::CHILDREN);
379: break;
380:
381: case IMP_Ftree_Prefs_Expanded::YES:
382: $this->_base->queue->setMailboxOpt('expand', 1);
383: $no_mbox = true;
384: break;
385:
386: case IMP_Ftree_Prefs_Expanded::LAST:
387: $filter->add($filter::EXPANDED);
388: $this->_base->queue->setMailboxOpt('expand', 1);
389: break;
390: }
391:
392: $filter->mboxes = array('INBOX');
393: $iterator->append($filter);
394:
395: if (!$no_mbox) {
396: $mboxes = IMP_Mailbox::formFrom(json_decode($this->vars->mboxes));
397: foreach ($mboxes as $val) {
398: if (!$val->inbox) {
399: $ancestors = new IMP_Ftree_IteratorFilter(
400: new IMP_Ftree_Iterator_Ancestors($val->tree_elt)
401: );
402: if ($this->vars->unsub) {
403: $ancestors->remove($ancestors::UNSUB);
404: }
405: $iterator->append($ancestors);
406: }
407: }
408: }
409: } else {
410: $filter->add($filter::EXPANDED);
411: $this->_base->queue->setMailboxOpt('expand', 1);
412:
413: foreach (array_filter(IMP_Mailbox::formFrom(json_decode($this->vars->mboxes))) as $val) {
414: $filter->iterator = new IMP_Ftree_Iterator($val->tree_elt);
415: $iterator->append($filter);
416: $ftree->expand($val);
417: }
418: }
419:
420: array_map(
421: array($ftree->eltdiff, 'add'),
422: array_unique(iterator_to_array($iterator, false))
423: );
424:
425: if ($this->vars->initial) {
426: $session->start();
427:
428: 429:
430: if (!$ftree->eltdiff->changed_elts) {
431: $this->vars->reload = true;
432: $this->listMailboxes();
433: $this->vars->reload = false;
434: }
435: }
436:
437: return true;
438: }
439:
440: 441: 442: 443: 444: 445: 446: 447:
448: public function dynamicInit()
449: {
450: $this->_base->callAction('viewPort');
451:
452: $this->vars->initial = 1;
453: $this->vars->mboxes = json_encode(array($this->vars->mailbox));
454: $this->listMailboxes();
455:
456: $this->_base->queue->flagConfig(Horde_Registry::VIEW_DYNAMIC);
457:
458: return true;
459: }
460:
461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472:
473: public function modifyPoll()
474: {
475: global $injector;
476:
477: if (!$this->vars->mbox) {
478: return false;
479: }
480:
481: $mbox = IMP_Mailbox::formFrom($this->vars->mbox);
482:
483: $result = new stdClass;
484: $result->add = intval($this->vars->add);
485: $result->mbox = $this->vars->mbox;
486:
487: if ($this->vars->add) {
488: $injector->getInstance('IMP_Ftree')->poll->addPollList($mbox);
489: $this->_base->queue->poll($mbox);
490: $GLOBALS['notification']->push(sprintf(_("\"%s\" mailbox now polled for new mail."), $mbox->display), 'horde.success');
491: } else {
492: $injector->getInstance('IMP_Ftree')->poll->removePollList($mbox);
493: $GLOBALS['notification']->push(sprintf(_("\"%s\" mailbox no longer polled for new mail."), $mbox->display), 'horde.success');
494: }
495:
496: return $result;
497: }
498:
499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509:
510: public function subscribe()
511: {
512: return IMP_Mailbox::formFrom($this->vars->mbox)->subscribe($this->vars->sub, array(
513: 'subfolders' => !empty($this->vars->subfolders)
514: ));
515: }
516:
517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528:
529: public function importMailbox()
530: {
531: global $injector, $notification;
532:
533: $mbox = IMP_Mailbox::formFrom($this->vars->import_mbox);
534:
535: try {
536: $notification->push($injector->getInstance('IMP_Mbox_Import')->import($mbox, 'import_file'), 'horde.success');
537: $this->_base->queue->poll($mbox);
538: } catch (Horde_Exception $e) {
539: $notification->push($e);
540: }
541:
542: $result = new stdClass;
543: $result->action = 'importMailbox';
544: $result->mbox = $this->vars->import_mbox;
545:
546: return new Horde_Core_Ajax_Response_HordeCore_JsonHtml($result);
547: }
548:
549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559:
560: public function flagMessages()
561: {
562: global $injector;
563:
564: if (!$this->vars->flags || !count($this->_base->indices)) {
565: return false;
566: }
567:
568: $change = $this->_base->changed(true);
569:
570: if (is_null($change)) {
571: return false;
572: }
573:
574: $flags = json_decode($this->vars->flags);
575:
576: 577: 578:
579: $system_flags = array(
580: Horde_Imap_Client::FLAG_ANSWERED,
581: Horde_Imap_Client::FLAG_DELETED,
582: Horde_Imap_Client::FLAG_DRAFT,
583: Horde_Imap_Client::FLAG_FLAGGED,
584: Horde_Imap_Client::FLAG_RECENT,
585: Horde_Imap_Client::FLAG_SEEN
586: );
587:
588: $unchangedsince = null;
589: if (!$this->_base->indices->mailbox->search &&
590: $this->vars->viewport->cacheid &&
591: array_diff($flags, $system_flags)) {
592: $imp_imap = $this->_base->indices->mailbox->imp_imap;
593: $parsed = $imp_imap->parseCacheId($this->vars->viewport->cacheid);
594:
595: try {
596: $unchangedsince[strval($this->_base->indices->mailbox)] = $imp_imap->sync($this->_base->indices->mailbox, $parsed['token'], array(
597: 'criteria' => Horde_Imap_Client::SYNC_UIDVALIDITY
598: ))->highestmodseq;
599: } catch (Horde_Imap_Client_Exception_Sync $e) {}
600: }
601:
602: $res = $injector->getInstance('IMP_Message')->flag(array(
603: ($this->vars->add ? 'add' : 'remove') => $flags
604: ), $this->_base->indices, array(
605: 'unchangedsince' => $unchangedsince
606: ));
607:
608: if (!$res) {
609: $this->_base->checkUidvalidity();
610: return false;
611: }
612:
613: if (in_array(Horde_Imap_Client::FLAG_SEEN, $flags)) {
614: $this->_base->queue->poll(array_keys($this->_base->indices->indices()));
615: }
616:
617: $this->_base->addTask('viewport', $change ? $this->_base->viewPortData(true) : new IMP_Ajax_Application_Viewport($this->_base->indices->mailbox));
618:
619: return true;
620: }
621:
622: 623: 624: 625: 626: 627: 628: 629:
630: public function addContact()
631: {
632: global $injector, $notification;
633:
634: $addr_ob = $injector->getInstance('IMP_Dynamic_AddressList')->parseAddressList($this->vars->addr);
635:
636:
637: $ob = $addr_ob[0];
638: if (!$ob) {
639: return false;
640: } elseif ($ob instanceof Horde_Mail_Rfc822_Group) {
641: $notification->push(_("Adding group lists not currently supported."), 'horde.warning');
642: return false;
643: }
644:
645: try {
646: $injector->getInstance('IMP_Contacts')->addAddress($ob->bare_address, $ob->personal);
647: $notification->push(sprintf(_("%s was successfully added to your address book."), $ob->label), 'horde.success');
648: return true;
649: } catch (Horde_Exception $e) {
650: $notification->push($e);
651: return false;
652: }
653: }
654:
655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665:
666: public function blacklist()
667: {
668: if (!count($this->_base->indices)) {
669: return false;
670: }
671:
672: if ($this->vars->blacklist) {
673: $change = $this->_base->changed(false);
674: if (!is_null($change)) {
675: try {
676: if ($GLOBALS['injector']->getInstance('IMP_Filter')->blacklistMessage($this->_base->indices, false)) {
677: $this->_base->deleteMsgs($this->_base->indices, $change);
678: return true;
679: }
680: } catch (Horde_Exception $e) {
681: $this->_base->checkUidvalidity();
682: }
683: }
684: } else {
685: try {
686: $GLOBALS['injector']->getInstance('IMP_Filter')->whitelistMessage($this->_base->indices, false);
687: return true;
688: } catch (Horde_Exception $e) {
689: $this->_base->checkUidvalidity();
690: }
691: }
692:
693: return false;
694: }
695:
696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710:
711: public function messageMimeTree()
712: {
713: $result = new stdClass;
714:
715: try {
716: $imp_contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create($this->_base->indices);
717: $result->tree = $imp_contents->getTree()->getTree(true);
718: } catch (IMP_Exception $e) {
719: if (!$this->vars->preview) {
720: throw $e;
721: }
722:
723: $result->preview->error = $e->getMessage();
724: $result->preview->errortype = 'horde.error';
725: $result->preview->buid = $this->vars->buid;
726: $result->preview->view = $this->vars->view;
727: }
728:
729: return $result;
730: }
731:
732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746:
747: public function ()
748: {
749: $show_msg = new IMP_Ajax_Application_ShowMessage($this->_base->indices);
750:
751: $hdr = $this->vars->header;
752:
753: $result = new stdClass;
754: $result->hdr_data->$hdr = (object)$show_msg->getAddressHeader($this->vars->header, null);
755:
756: return $result;
757: }
758:
759: 760: 761: 762: 763: 764: 765: 766: 767: 768:
769: public function deleteAttach()
770: {
771: global $injector, $notification;
772:
773: $result = array();
774:
775: if (isset($this->vars->atc_indices)) {
776: $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($this->vars->imp_compose);
777: foreach (json_decode($this->vars->atc_indices) as $val) {
778: if (isset($imp_compose[$val])) {
779: if (empty($this->vars->quiet)) {
780: $notification->push(sprintf(_("Deleted attachment \"%s\"."), Horde_Mime::decode($imp_compose[$val]->getPart()->getName(true))), 'horde.success');
781: }
782: unset($imp_compose[$val]);
783: $result[] = $val;
784: $this->_base->queue->compose($imp_compose);
785: }
786: }
787: }
788:
789: if (empty($result) && empty($this->vars->quiet)) {
790: $notification->push(_("At least one attachment could not be deleted."), 'horde.error');
791: }
792:
793: return $result;
794: }
795:
796: 797: 798: 799: 800: 801: 802: 803:
804: public function purgeDeleted()
805: {
806: global $injector;
807:
808: $change = $this->_base->changed(true);
809: if (is_null($change)) {
810: return false;
811: }
812:
813: if (!$change) {
814: $change = ($this->_base->indices->mailbox->getSort()->sortby == Horde_Imap_Client::SORT_THREAD);
815: }
816:
817: $expunged = $injector->getInstance('IMP_Message')->expungeMailbox(array(strval($this->_base->indices->mailbox) => 1), array('list' => true));
818:
819: if (!($expunge_count = count($expunged))) {
820: return false;
821: }
822:
823: $GLOBALS['notification']->push(sprintf(ngettext("%d message was purged from \"%s\".", "%d messages were purged from \"%s\".", $expunge_count), $expunge_count, $this->_base->indices->mailbox->display), 'horde.success');
824:
825: $indices = new IMP_Indices_Mailbox();
826: $indices->buids = $this->_base->indices->mailbox->toBuids($expunged);
827: $indices->mailbox = $this->_base->indices->mailbox;
828: $indices->indices = $expunged;
829:
830: $this->_base->deleteMsgs($indices, $change, true);
831: $this->_base->queue->poll($this->_base->indices->mailbox);
832:
833: return true;
834: }
835:
836: 837: 838: 839: 840: 841: 842: 843: 844:
845: public function sendMDN()
846: {
847: global $injector, $notification;
848:
849: if (count($this->_base->indices) != 1) {
850: return false;
851: }
852:
853: try {
854: $contents = $injector->getInstance('IMP_Factory_Contents')->create($this->_base->indices);
855: } catch (IMP_Imap_Exception $e) {
856: $e->notify(_("The Message Disposition Notification was not sent. This is what the server said") . ': ' . $e->getMessage());
857: return false;
858: }
859:
860: list($mbox, $uid) = $this->_base->indices->getSingle();
861: $injector->getInstance('IMP_Message_Ui')->MDNCheck(
862: new IMP_Indices($mbox, $uid),
863: $contents->getHeaderAndMarkAsSeen(),
864: true
865: );
866:
867: $notification->push(_("The Message Disposition Notification was sent successfully."), 'horde.success');
868:
869: $result = new stdClass;
870: $result->buid = $this->_base->vars->buid;
871: $result->mbox = $mbox->form_to;
872:
873: return $result;
874: }
875:
876: 877: 878: 879: 880: 881: 882: 883: 884: 885: 886:
887: public function stripAttachment()
888: {
889: global $injector, $notification;
890:
891: if (count($this->_base->indices) != 1) {
892: return false;
893: }
894:
895: $change = $this->_base->changed(true);
896: if (is_null($change)) {
897: return false;
898: }
899:
900: try {
901: $this->_base->indices = new IMP_Indices_Mailbox(
902: $this->_base->indices->mailbox,
903: $injector->getInstance('IMP_Message')->stripPart($this->_base->indices, $this->vars->id)
904: );
905: } catch (IMP_Exception $e) {
906: $notification->push($e);
907: return false;
908: }
909:
910: $notification->push(_("Attachment successfully stripped."), 'horde.success');
911:
912: $result = new stdClass;
913: list($result->newmbox, $result->newbuid) = $this->_base->indices->getSingle();
914: $result->newmbox = $result->newmbox->form_to;
915:
916: $this->_base->queue->message($this->_base->indices, true);
917: $this->_base->addTask('viewport', $this->_base->viewPortData(true));
918:
919: return $result;
920: }
921:
922: 923: 924: 925: 926: 927: 928: 929: 930: 931: 932: 933: 934: 935: 936:
937: public function html2Text()
938: {
939: return $this->_convertText('text');
940: }
941:
942: 943: 944: 945: 946: 947: 948: 949: 950: 951: 952: 953: 954: 955: 956:
957: public function text2Html()
958: {
959: return $this->_convertText('html');
960: }
961:
962: 963: 964: 965: 966:
967: protected function _convertText($mode)
968: {
969: global $injector;
970:
971: $compose = null;
972:
973: $result = new stdClass;
974: $result->text = array();
975:
976: foreach (json_decode($this->vars->data, true) as $key => $val) {
977: $tmp = null;
978:
979: if (empty($val['changed'])) {
980: if (!$compose) {
981: $compose = $this->_base->initCompose();
982: }
983:
984: switch ($compose->compose->replyType()) {
985: case IMP_Compose::FORWARD_BODY:
986: case IMP_Compose::FORWARD_BOTH:
987: $data = $compose->compose->forwardMessageText($compose->contents, array(
988: 'format' => $mode
989: ));
990: $tmp = $data['body'];
991: break;
992:
993: case IMP_Compose::REPLY_ALL:
994: case IMP_Compose::REPLY_LIST:
995: case IMP_Compose::REPLY_SENDER:
996: $data = $compose->compose->replyMessageText($compose->contents, array(
997: 'format' => $mode
998: ));
999: $tmp = $data['body'];
1000: break;
1001: }
1002: }
1003:
1004: $result->text[$key] = is_null($tmp)
1005: ? $injector->getInstance('IMP_Compose_Ui')->convertComposeText($val['text'], $mode)
1006: : $tmp;
1007: }
1008:
1009: return $result;
1010: }
1011:
1012: 1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023: 1024:
1025: public function addAttachmentCkeditor()
1026: {
1027: global $injector;
1028:
1029: $data = $url = null;
1030:
1031: if (isset($this->vars->composeCache)) {
1032: $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($this->vars->composeCache);
1033:
1034: if ($imp_compose->canUploadAttachment()) {
1035: try {
1036: $atc_ob = $imp_compose->addAttachmentFromUpload('upload');
1037: if ($atc_ob[0] instanceof IMP_Compose_Exception) {
1038: throw $atc_ob[0];
1039: }
1040:
1041: $atc_ob[0]->related = true;
1042:
1043: $data = array(
1044: IMP_Compose::RELATED_ATTR => 'src;' . $atc_ob[0]->id
1045: );
1046: $url = strval($atc_ob[0]->viewUrl());
1047: } catch (IMP_Compose_Exception $e) {
1048: $data = $e->getMessage();
1049: }
1050: } else {
1051: $data = _("Uploading attachments has been disabled on this server.");
1052: }
1053: } else {
1054: $data = _("Your attachment was not uploaded. Most likely, the file exceeded the maximum size allowed by the server configuration.");
1055: }
1056:
1057: return new Horde_Core_Ajax_Response_Raw(
1058: '<html>' .
1059: Horde::wrapInlineScript(array(
1060: 'window.parent.CKEDITOR.tools.callFunction(' . $this->vars->CKEditorFuncNum . ',' . json_encode($url) . ',' . json_encode($data) . ')'
1061: )) .
1062: '</html>',
1063: 'text/html'
1064: );
1065: }
1066:
1067: 1068: 1069: 1070: 1071: 1072: 1073: 1074: 1075: 1076:
1077: public function isFixedMbox()
1078: {
1079: $result = new stdClass;
1080: $result->fixed = !(IMP_Mailbox::formFrom($this->vars->mbox)->access_deletembox);
1081: return $result;
1082:
1083: }
1084:
1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094:
1095: public function createFlag()
1096: {
1097: global $injector, $notification;
1098:
1099: $ret = new stdClass;
1100: $ret->success = true;
1101:
1102: $imp_flags = $injector->getInstance('IMP_Flags');
1103:
1104: try {
1105: $imapflag = $imp_flags->addFlag($this->vars->flagname);
1106: } catch (IMP_Exception $e) {
1107: $notification->push($e, 'horde.error');
1108: $ret->success = false;
1109: return $ret;
1110: }
1111:
1112: if (!empty($this->vars->flagcolor)) {
1113: $imp_flags->updateFlag($this->vars->flagname, 'bgcolor', $this->vars->flagcolor);
1114: }
1115:
1116: $this->vars->add = true;
1117: $this->vars->flags = json_encode(array($imapflag));
1118: $this->flagMessages();
1119:
1120: $this->_base->queue->flagConfig(Horde_Registry::VIEW_DYNAMIC);
1121:
1122: $name = 'imp:viewport';
1123: if ($this->_base->tasks->$name) {
1124: $this->_base->tasks->$name->addFlagMetadata();
1125: }
1126:
1127: return $ret;
1128: }
1129:
1130: 1131: 1132: 1133: 1134: 1135: 1136: 1137:
1138: public function sentMailList()
1139: {
1140: global $injector;
1141:
1142: 1143:
1144: $identity = $injector->getInstance('IMP_Identity');
1145: foreach ($identity->getAllSentmail() as $mbox) {
1146: $mbox->create();
1147: }
1148:
1149: $flist = array();
1150: $iterator = new IMP_Ftree_IteratorFilter($injector->getInstance('IMP_Ftree'));
1151: $iterator->add($iterator::NONIMAP);
1152:
1153: foreach ($iterator as $val) {
1154: $mbox_ob = $val->mbox_ob;
1155: $tmp = array(
1156: 'f' => $mbox_ob->display,
1157: 'l' => Horde_String::abbreviate(str_repeat(' ', 2 * $val->level) . $mbox_ob->basename, 30),
1158: 'v' => $val->container ? '' : $mbox_ob->form_to
1159: );
1160: if ($tmp['f'] == $tmp['v']) {
1161: unset($tmp['f']);
1162: }
1163: $flist[] = $tmp;
1164: }
1165:
1166: $ret = new stdClass;
1167: $ret->flist = $flist;
1168:
1169: return $ret;
1170: }
1171:
1172: 1173: 1174: 1175: 1176: 1177: 1178: 1179: 1180: 1181: 1182: 1183:
1184: public function newFilter()
1185: {
1186: global $injector, $notification, $registry;
1187:
1188: if (isset($this->vars->addr)) {
1189: $addr_ob = $injector->getInstance('IMP_Dynamic_AddressList')->parseAddressList($this->vars->addr);
1190: } else {
1191: $query = new Horde_Imap_Client_Fetch_Query();
1192: $query->envelope();
1193:
1194: $imp_imap = $this->_base->indices->mailbox->imp_imap;
1195: list($mbox, $uid) = $this->_base->indices->getSingle();
1196: $ret = $imp_imap->fetch($mbox, $query, array(
1197: 'ids' => $imp_imap->getIdsOb($uid)
1198: ));
1199:
1200: $addr_ob = $ret[$uid]->getEnvelope()->from;
1201: }
1202:
1203:
1204: $ob = $addr_ob[0];
1205: if (!$ob) {
1206: return false;
1207: } elseif ($ob instanceof Horde_Mail_Rfc822_Group) {
1208: $notification->push(_("Editing group lists not currently supported."), 'horde.warning');
1209: return false;
1210: }
1211:
1212: try {
1213: return new Horde_Core_Ajax_Response_HordeCore_Reload(
1214: $registry->link('mail/newEmailFilter', array(
1215: 'email' => $ob->bare_address
1216: ))
1217: );
1218: } catch (Horde_Exception $e) {
1219: return false;
1220: }
1221: }
1222:
1223: 1224: 1225: 1226: 1227: 1228: 1229: 1230: 1231: 1232: 1233:
1234: public function getContactsImage()
1235: {
1236: $contacts_img = new IMP_Contacts_Image($this->vars->addr);
1237: $out = new stdClass;
1238:
1239: try {
1240: $res = $contacts_img->getImage($contacts_img::AVATAR);
1241: $out->avatar = strval($res['url']);
1242: } catch (IMP_Exception $e) {}
1243:
1244: try {
1245: $res = $contacts_img->getImage($contacts_img::FLAG);
1246: $out->flag = strval($res['url']);
1247: $out->flagname = $res['desc'];
1248: } catch (IMP_Exception $e) {}
1249:
1250: return $out;
1251: }
1252:
1253: 1254: 1255: 1256: 1257: 1258: 1259: 1260: 1261: 1262:
1263: public function mailboxSize()
1264: {
1265: $mbox = IMP_Mailbox::formFrom($this->vars->mbox);
1266:
1267: $ret = new stdClass;
1268: $ret->size = $mbox->size;
1269:
1270: return $ret;
1271: }
1272:
1273: 1274: 1275: 1276: 1277: 1278: 1279: 1280: 1281: 1282: 1283: 1284: 1285: 1286: 1287: 1288: 1289:
1290: public function autocompleteSearch()
1291: {
1292: $out = new stdClass;
1293: $out->results = array();
1294:
1295: switch ($this->vars->type) {
1296: case 'email':
1297: $addr = $GLOBALS['injector']->getInstance('IMP_Contacts')->searchEmail(
1298: $this->vars->search,
1299: array('levenshtein' => true)
1300: );
1301:
1302: $out->results = $this->_autocompleteSearchEmail($addr);
1303: break;
1304: }
1305:
1306: return $out;
1307: }
1308:
1309: 1310: 1311: 1312: 1313: 1314: 1315:
1316: protected function _autocompleteSearchEmail(Horde_Mail_Rfc822_List $alist)
1317: {
1318: $out = array();
1319:
1320: foreach ($alist as $val) {
1321: $tmp = array('v' => strval($val));
1322: $l = $val->writeAddress(array('noquote' => true));
1323: $s = $val->label;
1324:
1325: if ($l !== $tmp['v']) {
1326: $tmp['l'] = $l;
1327: }
1328:
1329: if ($val instanceof Horde_Mail_Rfc822_Group) {
1330: $tmp['g'] = $this->_autocompleteSearchEmail($val->addresses);
1331: $tmp['s'] = sprintf(
1332: _("%s [%d addresses]"),
1333: $s,
1334: count($val)
1335: );
1336: } elseif ($s !== $tmp['v']) {
1337: $tmp['s'] = $s;
1338: }
1339:
1340: $out[] = $tmp;
1341: }
1342:
1343: return $out;
1344: }
1345:
1346: }
1347: