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_Dynamic_Compose extends IMP_Dynamic_Base
24: {
25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40:
41: protected function _init()
42: {
43: global $injector, $notification, $page_output, $prefs, $session;
44:
45: $alist = $injector->getInstance('IMP_Dynamic_AddressList');
46: $clink = new IMP_Compose_Link($this->vars);
47:
48: $addr = array();
49: foreach (array('to', 'cc', 'bcc') as $val) {
50: $var_name = $val . '_json';
51: if (isset($this->vars->$var_name)) {
52:
53: $addr[$val] = $alist->parseAddressList($this->vars->$var_name);
54: } elseif (isset($clink->args[$val])) {
55:
56: $addr[$val] = IMP::parseAddressList($clink->args[$val]);
57: }
58: }
59:
60: $subject = isset($clink->args['subject'])
61: ? $clink->args['subject']
62: : null;
63:
64: $identity = $injector->getInstance('IMP_Identity');
65: if (!$prefs->isLocked('default_identity') &&
66: isset($this->vars->identity)) {
67: $identity->setDefault($this->vars->identity);
68: }
69:
70:
71: $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create();
72: $compose_ajax = new IMP_Ajax_Application_Compose($imp_compose, $this->vars->type);
73:
74: $ajax_queue = $injector->getInstance('IMP_Ajax_Queue');
75: $ajax_queue->compose($imp_compose);
76:
77: $compose_opts = array(
78: 'title' => _("New Message")
79: );
80:
81: switch ($this->vars->type) {
82: case 'reply':
83: case 'reply_all':
84: case 'reply_auto':
85: case 'reply_list':
86: try {
87: $result = $imp_compose->replyMessage(
88: $compose_ajax->reply_map[$this->vars->type],
89: $this->_getContents(),
90: array(
91: 'to' => isset($addr['to']) ? $addr['to'] : null
92: )
93: );
94: } catch (IMP_Exception $e) {
95: $notification->push($e, 'horde.error');
96: break;
97: }
98:
99: $onload = $compose_ajax->getResponse($result);
100:
101: switch ($result['type']) {
102: case IMP_Compose::REPLY_SENDER:
103: $compose_opts['title'] = _("Reply");
104: break;
105:
106: case IMP_Compose::REPLY_ALL:
107: $compose_opts['title'] = _("Reply to All");
108: break;
109:
110: case IMP_Compose::REPLY_LIST:
111: $compose_opts['title'] = _("Reply to List");
112: break;
113: }
114: $compose_opts['title'] .= ': ' . $result['subject'];
115: break;
116:
117: case 'forward_attach':
118: case 'forward_auto':
119: case 'forward_body':
120: case 'forward_both':
121: try {
122: if (count($this->indices) > 1) {
123: if (!in_array($this->vars->type, array('forward_attach', 'forward_auto'))) {
124: $notification->push(_("Multiple messages can only be forwarded as attachments."), 'horde.warning');
125: }
126:
127: $result = $imp_compose->forwardMultipleMessages($this->indices);
128: } else {
129: $result = $imp_compose->forwardMessage(
130: $compose_ajax->forward_map[$this->vars->type],
131: $this->_getContents()
132: );
133: }
134: } catch (IMP_Exception $e) {
135: $notification->push($e, 'horde.error');
136: break;
137: }
138:
139: $onload = $compose_ajax->getResponse($result);
140: $compose_opts['title'] = $result['title'];
141:
142: $ajax_queue->attachment($imp_compose, IMP_Compose::FORWARD_ATTACH);
143: break;
144:
145: case 'forward_redirect':
146: try {
147: $imp_compose->redirectMessage($this->indices);
148: $compose_opts['title'] = _("Redirect");
149: } catch (IMP_Compose_Exception $e) {
150: $notification->push($e, 'horde.error');
151: }
152:
153: $onload = new stdClass;
154: break;
155:
156: case 'editasnew':
157: case 'resume':
158: case 'template':
159: case 'template_edit':
160: try {
161: switch ($this->vars->type) {
162: case 'editasnew':
163: $result = $imp_compose->editAsNew($this->indices);
164: break;
165:
166: case 'resume':
167: $result = $imp_compose->resumeDraft($this->indices);
168: $compose_opts['resume'] = true;
169: break;
170:
171: case 'template':
172: $result = $imp_compose->useTemplate($this->indices);
173: break;
174:
175: case 'template_edit':
176: $result = $imp_compose->editTemplate($this->indices);
177: $compose_opts['template'] = true;
178: break;
179: }
180:
181: $onload = $compose_ajax->getResponse($result);
182:
183: $ajax_queue->attachment($imp_compose, $result['type']);
184:
185: $show_editor = ($result['format'] == 'html');
186: } catch (IMP_Compose_Exception $e) {
187: $notification->push($e);
188: }
189: break;
190:
191: case 'new_to':
192: $h = $this->_getContents()->getHeader();
193: $addr['to'] = $h->getOb('reply-to') ?: $h->getOb('from');
194:
195:
196: case 'new':
197: case 'template_new':
198: default:
199: $show_editor = ($prefs->getValue('compose_html') && $session->get('imp', 'rteavail'));
200:
201: $onload = $compose_ajax->getBaseResponse();
202: $onload->body = isset($clink->args['body'])
203: ? strval($clink->args['body'])
204: : '';
205: if ($show_editor) {
206: $onload->format = 'html';
207: }
208:
209: if ($this->vars->type == 'template_new') {
210: $compose_opts['template'] = true;
211: }
212: break;
213: }
214:
215: $compose_opts['redirect'] = ($this->vars->type == 'forward_redirect');
216:
217: if (isset($onload->addr) || !empty($addr)) {
218: foreach (array('to', 'cc', 'bcc') as $val) {
219: if (!isset($onload->addr[$val])) {
220: $onload->addr[$val] = array();
221: }
222: if (isset($addr[$val])) {
223: $onload->addr[$val] = array_merge(
224: $onload->addr[$val],
225: array_map('strval', $addr[$val]->base_addresses)
226: );
227: }
228: }
229: }
230:
231: if (!is_null($subject)) {
232: $onload->subject = $subject;
233: }
234:
235: $this->title = $compose_opts['title'];
236: $this->view->compose = $injector->getInstance('IMP_Dynamic_Compose_Common')->compose($this, $compose_opts);
237:
238: $page_output->addInlineJsVars(array(
239: 'DimpCompose.onload_show' => $onload,
240: 'DimpCompose.tasks' => $injector->getInstance('Horde_Core_Factory_Ajax')->create('imp', $this->vars)->getTasks()
241: ));
242:
243: Horde::startBuffer();
244: $notification->notify(array(
245: 'listeners' => array('status', 'audio')
246: ));
247: $this->view->status = Horde::endBuffer();
248:
249: $this->_pages[] = 'compose-base';
250: }
251:
252: 253:
254: public static function url(array $opts = array())
255: {
256: return Horde::url('dynamic.php')->add('page', 'compose');
257: }
258:
259: 260: 261: 262: 263: 264: 265: 266:
267: protected function _getContents()
268: {
269: if (!is_null($this->indices)) {
270: try {
271: return $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create($this->indices);
272: } catch (Horde_Exception $e) {}
273: }
274:
275: $this->vars->buid = null;
276: $this->vars->type = 'new';
277:
278: throw new IMP_Exception(_("Could not retrieve message data from the mail server."));
279: }
280:
281: }
282: