59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * compose.php |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This code sends a mail. |
10 | * |
11 | * There are 4 modes of operation: |
12 | * - Start new mail |
13 | * - Add an attachment |
14 | * - Send mail |
15 | * - Save As Draft |
16 | * |
17 | * $Id$ |
18 | */ |
f7fb20fe |
19 | |
86725763 |
20 | /* Path for SquirrelMail required files. */ |
21 | define('SM_PATH','../'); |
22 | |
23 | /* SquirrelMail required files. */ |
08185f2a |
24 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
25 | require_once(SM_PATH . 'functions/imap.php'); |
26 | require_once(SM_PATH . 'functions/date.php'); |
27 | require_once(SM_PATH . 'functions/mime.php'); |
28 | //require_once(SM_PATH . 'functions/smtp.php'); |
29 | require_once(SM_PATH . 'functions/plugin.php'); |
30 | require_once(SM_PATH . 'functions/display_messages.php'); |
31 | require_once(SM_PATH . 'class/deliver/Deliver.class.php'); |
91f2085b |
32 | |
09044055 |
33 | /* --------------------- Specific Functions ------------------------------ */ |
41b94d65 |
34 | function replyAllString($header) { |
35 | global $include_self_reply_all, $username, $data_dir; |
36 | $excl_arr = array(); |
37 | /** |
38 | * 1) Remove the addresses we'll be sending the message 'to' |
39 | */ |
40 | $url_replytoall_avoid_addrs = ''; |
41 | if (isset($header->replyto)) { |
42 | $excl_ar = $header->getAddr_a('replyto'); |
43 | } |
44 | /** |
45 | * 2) Remove our identities from the CC list (they still can be in the |
46 | * TO list) only if $include_self_reply_all is turned off |
47 | */ |
48 | if (!$include_self_reply_all) { |
49 | $email_address = trim(getPref($data_dir, $username, 'email_address')); |
50 | $excl_ar[$email_address] = ''; |
51 | |
52 | $idents = getPref($data_dir, $username, 'identities'); |
53 | if ($idents != '' && $idents > 1) { |
54 | for ($i = 1; $i < $idents; $i ++) { |
55 | $cur_email_address = getPref($data_dir, $username, |
56 | 'email_address' . $i); |
57 | $cur_email_address = strtolower($cur_email_address); |
a61878d0 |
58 | $excl_ar[$cur_email_address] = ''; |
41b94d65 |
59 | } |
60 | } |
61 | } |
62 | |
63 | /** |
64 | * 3) get the addresses. |
65 | */ |
66 | $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar); |
67 | |
68 | /** |
69 | * 4) generate the string. |
70 | */ |
71 | $url_replytoallcc = ''; |
72 | foreach( $url_replytoall_ar as $email => $personal) { |
73 | if ($personal) { |
a61878d0 |
74 | $url_replytoallcc .= ", \"$personal\" <$email>"; |
41b94d65 |
75 | } else { |
a61878d0 |
76 | $url_replytoallcc .= ', '. $email; |
41b94d65 |
77 | } |
78 | } |
79 | $url_replytoallcc = substr($url_replytoallcc,2); |
80 | return $url_replytoallcc; |
09044055 |
81 | } |
82 | |
41b94d65 |
83 | function getforwardHeader($orig_header) { |
19c6f7a7 |
84 | global $editor_size; |
85 | |
a61878d0 |
86 | $display = array( _("Subject") => strlen(_("Subject")), |
87 | _("From") => strlen(_("From")), |
88 | _("Date") => strlen(_("Date")), |
89 | _("To") => strlen(_("To")), |
90 | _("Cc") => strlen(_("Cc")) ); |
a45887d7 |
91 | $maxsize = max($display); |
92 | $indent = str_pad('',$maxsize+2); |
93 | foreach($display as $key => $val) { |
94 | $display[$key] = $key .': '. str_pad('', $maxsize - $val); |
95 | } |
a61878d0 |
96 | $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) . |
97 | "\n". $display[_("Subject")] . |
98 | decodeHeader($orig_header->subject) . "\n" . |
99 | $display[_("From")] . |
100 | decodeHeader($orig_header->getAddr_s('from',"\n$indent")) . "\n" . |
101 | $display[_("Date")] . |
102 | getLongDateString( $orig_header->date ). "\n" . |
103 | $display[_("To")] . |
104 | decodeHeader($orig_header->getAddr_s('to',"\n$indent")) ."\n"; |
41b94d65 |
105 | if ($orig_header->cc != array() && $orig_header->cc !='') { |
c4d02444 |
106 | $bodyTop .= $display[_("Cc")] . decodeHeader($orig_header->getAddr_s('cc',"\n$indent")) . "\n"; |
41b94d65 |
107 | } |
a61878d0 |
108 | $bodyTop .= str_pad('', $editor_size -2 , '-') . |
109 | "\n"; |
41b94d65 |
110 | return $bodyTop; |
111 | } |
09044055 |
112 | /* ----------------------------------------------------------------------- */ |
113 | |
5628fdde |
114 | /* OLD: should be adapted to composeMessage */ |
115 | |
44560457 |
116 | /* |
117 | * If the session is expired during a post this restores the compose session |
118 | * vars. |
119 | */ |
120 | //$session_expired = false; |
121 | if (session_is_registered('session_expired_post')) { |
40934000 |
122 | global $session_expired_post, $session_expired; |
123 | /* |
124 | * extra check for username so we don't display previous post data from |
125 | * another user during this session. |
126 | */ |
127 | if ($session_expired_post['username'] != $username) { |
128 | session_unregister('session_expired_post'); |
129 | session_unregister('session_expired'); |
130 | } else { |
131 | foreach ($session_expired_post as $postvar => $val) { |
132 | if (isset($val)) { |
133 | $$postvar = $val; |
134 | } else { |
135 | $$postvar = ''; |
136 | } |
137 | } |
138 | if (isset($send)) { |
139 | unset($send); |
140 | } |
141 | $session_expired = true; |
142 | } |
143 | session_unregister('session_expired_post'); |
144 | session_unregister('session_expired'); |
145 | if (!isset($mailbox)) { |
146 | $mailbox = ''; |
147 | } |
148 | if ($compose_new_win == '1') { |
149 | compose_Header($color, $mailbox); |
150 | } else { |
151 | displayPageHeader($color, $mailbox); |
152 | } |
153 | showInputForm($session, false); |
154 | exit(); |
44560457 |
155 | } |
156 | |
da95c4b6 |
157 | if (!isset($composesession)) { |
158 | $composesession = 0; |
a43e4b90 |
159 | sqsession_register(0,'composesession'); |
da95c4b6 |
160 | } |
161 | |
d7f8e6e6 |
162 | if (!isset($session) || (isset($newmessage) && $newmessage)) { |
da95c4b6 |
163 | $session = "$composesession" +1; |
91f2085b |
164 | $composesession = $session; |
a43e4b90 |
165 | sqsession_register($composesession,'composesession'); |
d7f8e6e6 |
166 | } |
da95c4b6 |
167 | |
a43e4b90 |
168 | if (!isset($compose_messages)) { |
169 | $compose_messages = array(); |
170 | } |
40934000 |
171 | if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) { |
172 | /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */ |
5628fdde |
173 | $composeMessage = new Message(); |
a43e4b90 |
174 | $rfc822_header = new Rfc822Header(); |
175 | $composeMessage->rfc822_header = $rfc822_header; |
176 | $composeMessage->reply_rfc822_header = ''; |
177 | $compose_messages[$session] = $composeMessage; |
5628fdde |
178 | sqsession_register($compose_messages,'compose_messages'); |
179 | } else { |
180 | $composeMessage=$compose_messages[$session]; |
a43e4b90 |
181 | } |
a43e4b90 |
182 | |
00793a25 |
183 | if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) { |
184 | $mailbox = 'INBOX'; |
185 | } |
186 | |
187 | if (isset($draft)) { |
b48d3c53 |
188 | /* |
189 | * Set $default_charset to correspond with the user's selection |
190 | * of language interface. |
191 | */ |
192 | set_my_charset(); |
193 | $composeMessage=$compose_messages[$session]; |
194 | $Result = sendMessage($composeMessage, true); |
195 | |
196 | if (! sendMessage($composeMessage, true)) { |
da95c4b6 |
197 | showInputForm($session); |
00793a25 |
198 | exit(); |
734f4ee6 |
199 | } else { |
00793a25 |
200 | $draft_message = _("Draft Email Saved"); |
201 | /* If this is a resumed draft, then delete the original */ |
202 | if(isset($delete_draft)) { |
7058a2a9 |
203 | Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) . |
fae72101 |
204 | "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes"); |
00793a25 |
205 | exit(); |
7058a2a9 |
206 | } |
9c3e6cd4 |
207 | else { |
208 | if ($compose_new_win == '1') { |
da95c4b6 |
209 | Header("Location: compose.php?saved_draft=yes&session=$composesession"); |
a61878d0 |
210 | exit(); |
9c3e6cd4 |
211 | } |
212 | else { |
a61878d0 |
213 | Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort". |
214 | "&startMessage=1¬e=".urlencode($draft_message)); |
215 | exit(); |
9c3e6cd4 |
216 | } |
00793a25 |
217 | } |
218 | } |
219 | } |
220 | |
221 | if (isset($send)) { |
222 | if (isset($HTTP_POST_FILES['attachfile']) && |
223 | $HTTP_POST_FILES['attachfile']['tmp_name'] && |
224 | $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { |
da95c4b6 |
225 | $AttachFailure = saveAttachedFiles($session); |
00793a25 |
226 | } |
227 | if (checkInput(false) && !isset($AttachFailure)) { |
228 | $urlMailbox = urlencode (trim($mailbox)); |
3f6b1b6f |
229 | if (! isset($passed_id)) { |
230 | $passed_id = 0; |
00793a25 |
231 | } |
232 | /* |
233 | * Set $default_charset to correspond with the user's selection |
7058a2a9 |
234 | * of language interface. |
00793a25 |
235 | */ |
236 | set_my_charset(); |
00793a25 |
237 | /* |
238 | * This is to change all newlines to \n |
7058a2a9 |
239 | * We'll change them to \r\n later (in the sendMessage function) |
00793a25 |
240 | */ |
241 | $body = str_replace("\r\n", "\n", $body); |
242 | $body = str_replace("\r", "\n", $body); |
243 | |
244 | /* |
245 | * Rewrap $body so that no line is bigger than $editor_size |
246 | * This should only really kick in the sqWordWrap function |
f302d704 |
247 | * if the browser doesn't support "VIRTUAL" as the wrap type. |
00793a25 |
248 | */ |
249 | $body = explode("\n", $body); |
250 | $newBody = ''; |
251 | foreach ($body as $line) { |
252 | if( $line <> '-- ' ) { |
253 | $line = rtrim($line); |
254 | } |
255 | if (strlen($line) <= $editor_size + 1) { |
256 | $newBody .= $line . "\n"; |
734f4ee6 |
257 | } else { |
e0858036 |
258 | sqWordWrap($line, $editor_size); |
259 | $newBody .= $line . "\n"; |
00793a25 |
260 | } |
261 | } |
262 | $body = $newBody; |
e02775fe |
263 | do_hook('compose_send'); |
a43e4b90 |
264 | $composeMessage=$compose_messages[$session]; |
265 | $Result = sendMessage($composeMessage); |
00793a25 |
266 | if (! $Result) { |
da95c4b6 |
267 | showInputForm($session); |
00793a25 |
268 | exit(); |
269 | } |
270 | if ( isset($delete_draft)) { |
7058a2a9 |
271 | Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ). |
fae72101 |
272 | "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes"); |
00793a25 |
273 | exit(); |
274 | } |
9c3e6cd4 |
275 | if ($compose_new_win == '1') { |
d7f8e6e6 |
276 | Header("Location: compose.php?mail_sent=yes"); |
9c3e6cd4 |
277 | } |
278 | else { |
fae72101 |
279 | Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort". |
280 | "&startMessage=1"); |
9c3e6cd4 |
281 | } |
734f4ee6 |
282 | } else { |
00793a25 |
283 | /* |
284 | *$imapConnection = sqimap_login($username, $key, $imapServerAddress, |
285 | * $imapPort, 0); |
286 | */ |
9c3e6cd4 |
287 | if ($compose_new_win == '1') { |
288 | compose_Header($color, $mailbox); |
289 | } |
290 | else { |
291 | displayPageHeader($color, $mailbox); |
292 | } |
00793a25 |
293 | if (isset($AttachFailure)) { |
294 | plain_error_message(_("Could not move/copy file. File not attached"), |
295 | $color); |
296 | } |
00793a25 |
297 | checkInput(true); |
da95c4b6 |
298 | showInputForm($session); |
00793a25 |
299 | /* sqimap_logout($imapConnection); */ |
300 | } |
e02775fe |
301 | } elseif (isset($html_addr_search_done)) { |
9c3e6cd4 |
302 | if ($compose_new_win == '1') { |
303 | compose_Header($color, $mailbox); |
304 | } |
305 | else { |
306 | displayPageHeader($color, $mailbox); |
307 | } |
00793a25 |
308 | |
309 | if (isset($send_to_search) && is_array($send_to_search)) { |
310 | foreach ($send_to_search as $k => $v) { |
311 | if (substr($k, 0, 1) == 'T') { |
312 | if ($send_to) { |
313 | $send_to .= ', '; |
314 | } |
315 | $send_to .= $v; |
316 | } |
317 | elseif (substr($k, 0, 1) == 'C') { |
318 | if ($send_to_cc) { |
319 | $send_to_cc .= ', '; |
320 | } |
321 | $send_to_cc .= $v; |
322 | } |
323 | elseif (substr($k, 0, 1) == 'B') { |
324 | if ($send_to_bcc) { |
325 | $send_to_bcc .= ', '; |
326 | } |
327 | $send_to_bcc .= $v; |
328 | } |
329 | } |
330 | } |
da95c4b6 |
331 | showInputForm($session); |
e02775fe |
332 | } elseif (isset($html_addr_search)) { |
00793a25 |
333 | if (isset($HTTP_POST_FILES['attachfile']) && |
334 | $HTTP_POST_FILES['attachfile']['tmp_name'] && |
335 | $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { |
da95c4b6 |
336 | if (saveAttachedFiles($session)) { |
00793a25 |
337 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
338 | } |
339 | } |
340 | /* |
341 | * I am using an include so as to elminiate an extra unnecessary |
342 | * click. If you can think of a better way, please implement it. |
343 | */ |
344 | include_once('./addrbook_search_html.php'); |
e02775fe |
345 | } elseif (isset($attach)) { |
da95c4b6 |
346 | if (saveAttachedFiles($session)) { |
00793a25 |
347 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
348 | } |
9c3e6cd4 |
349 | if ($compose_new_win == '1') { |
350 | compose_Header($color, $mailbox); |
351 | } |
352 | else { |
353 | displayPageHeader($color, $mailbox); |
354 | } |
da95c4b6 |
355 | showInputForm($session); |
01265fba |
356 | } |
357 | elseif (isset($sigappend)) { |
358 | $idents = getPref($data_dir, $username, 'identities', 0); |
359 | if ($idents > 1) { |
360 | if ($identity == 'default') { |
361 | $no = 'g'; |
362 | } else { |
363 | $no = $identity; |
364 | } |
365 | $signature = getSig($data_dir, $username, $no); |
366 | } |
367 | $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature; |
368 | if ($compose_new_win == '1') { |
369 | compose_Header($color, $mailbox); |
370 | } else { |
371 | displayPageHeader($color, $mailbox); |
372 | } |
da95c4b6 |
373 | showInputForm($session); |
e02775fe |
374 | } elseif (isset($do_delete)) { |
9c3e6cd4 |
375 | if ($compose_new_win == '1') { |
376 | compose_Header($color, $mailbox); |
377 | } |
378 | else { |
379 | displayPageHeader($color, $mailbox); |
380 | } |
00793a25 |
381 | |
00793a25 |
382 | if (isset($delete) && is_array($delete)) { |
a43e4b90 |
383 | $composeMessage = $compose_messages[$session]; |
00793a25 |
384 | foreach($delete as $index) { |
a43e4b90 |
385 | $attached_file = $composeMessage->entities[$index]->att_local_name; |
a61878d0 |
386 | unlink ($attached_file); |
a43e4b90 |
387 | unset ($composeMessage->entities[$index]); |
00793a25 |
388 | } |
a43e4b90 |
389 | $new_entities = array(); |
390 | foreach ($composeMessage->entities as $entity) { |
391 | $new_entities[] = $entity; |
392 | } |
393 | $composeMessage->entities = $new_entities; |
394 | $compose_messages[$session] = $composeMessage; |
395 | sqsession_register($compose_messages, 'compose_messages'); |
396 | // setPref($data_dir, $username, 'attachments', serialize($attachments)); |
00793a25 |
397 | } |
da95c4b6 |
398 | showInputForm($session); |
734f4ee6 |
399 | } else { |
00793a25 |
400 | /* |
401 | * This handles the default case as well as the error case |
402 | * (they had the same code) --> if (isset($smtpErrors)) |
403 | */ |
44560457 |
404 | |
405 | if ($compose_new_win == '1') { |
406 | compose_Header($color, $mailbox); |
407 | } else { |
408 | displayPageHeader($color, $mailbox); |
409 | } |
00793a25 |
410 | |
411 | $newmail = true; |
412 | |
a61878d0 |
413 | if (!isset($passed_ent_id)) { |
414 | $passed_ent_id = ''; |
415 | } |
416 | if (!isset($passed_id)) { |
417 | $passed_id = ''; |
418 | } |
419 | if (!isset($mailbox)) { |
420 | $mailbox = ''; |
421 | } |
422 | if (!isset($action)) { |
423 | $action = ''; |
424 | } |
41b94d65 |
425 | |
44560457 |
426 | $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session); |
b9928adc |
427 | |
428 | /* in case the origin is not read_body.php */ |
429 | if (isset($send_to)) { |
430 | $values['send_to'] = $send_to; |
431 | } |
432 | if (isset($send_to_cc)) { |
44560457 |
433 | $values['send_to_cc'] = $send_to_cc; |
b9928adc |
434 | } |
435 | if (isset($send_to_bcc)) { |
44560457 |
436 | $values['send_to_bcc'] = $send_to_bcc; |
b9928adc |
437 | } |
41b94d65 |
438 | showInputForm($session, $values); |
00793a25 |
439 | } |
440 | |
441 | exit(); |
442 | |
00793a25 |
443 | /**************** Only function definitions go below *************/ |
444 | |
445 | |
48985d59 |
446 | /* This function is used when not sending or adding attachments */ |
44560457 |
447 | function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') { |
91f2085b |
448 | global $editor_size, $default_use_priority, $body, |
44560457 |
449 | $use_signature, $composesession, $data_dir, $username, |
a43e4b90 |
450 | $username, $key, $imapServerAddress, $imapPort, $compose_messages, |
451 | $composeMessage; |
e7f1a81d |
452 | |
91f2085b |
453 | $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; |
bdb92db3 |
454 | $mailprio = 3; |
44560457 |
455 | |
41b94d65 |
456 | if ($passed_id) { |
44560457 |
457 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
a61878d0 |
458 | $imapPort, 0); |
459 | |
48985d59 |
460 | sqimap_mailbox_select($imapConnection, $mailbox); |
41b94d65 |
461 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
a43e4b90 |
462 | |
a61878d0 |
463 | $body = ''; |
464 | if ($passed_ent_id) { |
465 | /* redefine the messsage in case of message/rfc822 */ |
466 | $message = $message->getEntity($passed_ent_id); |
467 | /* message is an entity which contains the envelope and type0=message |
468 | * and type1=rfc822. The actual entities are childs from |
469 | * $message->entities[0]. That's where the encoding and is located |
470 | */ |
471 | |
472 | $entities = $message->entities[0]->findDisplayEntity |
473 | (array(), $alt_order = array('text/plain')); |
474 | if (!count($entities)) { |
475 | $entities = $message->entities[0]->findDisplayEntity |
476 | (array(), $alt_order = array('text/plain','html/plain')); |
477 | } |
478 | $orig_header = $message->rfc822_header; /* here is the envelope located */ |
479 | /* redefine the message for picking up the attachments */ |
480 | $message = $message->entities[0]; |
481 | |
482 | } else { |
483 | $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain')); |
484 | if (!count($entities)) { |
485 | $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain')); |
486 | } |
487 | $orig_header = $message->rfc822_header; |
488 | } |
a43e4b90 |
489 | |
41b94d65 |
490 | $encoding = $message->header->encoding; |
a61878d0 |
491 | $type0 = $message->type0; |
492 | $type1 = $message->type1; |
41b94d65 |
493 | foreach ($entities as $ent) { |
a61878d0 |
494 | $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); |
495 | $body_part_entity = $message->getEntity($ent); |
496 | $bodypart = decodeBody($unencoded_bodypart, |
497 | $body_part_entity->header->encoding); |
498 | if ($type1 == 'html') { |
499 | $bodypart = strip_tags($bodypart); |
500 | } |
501 | $body .= $bodypart; |
502 | } |
503 | if ($default_use_priority) { |
504 | $mailprio = substr($orig_header->priority,0,1); |
505 | if (!$mailprio) { |
506 | $mailprio = 3; |
507 | } |
508 | } else { |
509 | $mailprio = ''; |
510 | } |
a43e4b90 |
511 | //ClearAttachments($session); |
bdb92db3 |
512 | |
513 | $identity = ''; |
514 | $idents = getPref($data_dir, $username, 'identities'); |
a45887d7 |
515 | $from_o = $orig_header->from; |
bdb92db3 |
516 | if (is_object($from_o)) { |
517 | $orig_from = $from_o->getAddress(); |
518 | } else { |
519 | $orig_from = ''; |
a61878d0 |
520 | } |
bdb92db3 |
521 | if (!empty($idents) && $idents > 1) { |
a61878d0 |
522 | for ($i = 1; $i < $idents; $i++) { |
523 | $enc_from_name = '"'. |
524 | getPref($data_dir, |
525 | $username, |
526 | 'full_name' . $i) . |
527 | '" <' . getPref($data_dir, $username, |
528 | 'email_address' . $i) . '>'; |
529 | if ($enc_from_name == $orig_from) { |
530 | $identity = $i; |
531 | break; |
532 | } |
533 | } |
bdb92db3 |
534 | } |
a61878d0 |
535 | |
536 | switch ($action) { |
537 | case ('draft'): |
538 | $use_signature = FALSE; |
c3d1d2cf |
539 | $send_to = decodeHeader($orig_header->getAddr_s('to')); |
540 | $send_to_cc = decodeHeader($orig_header->getAddr_s('cc')); |
541 | $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc')); |
a61878d0 |
542 | $subject = decodeHeader($orig_header->subject); |
543 | |
544 | $body_ary = explode("\n", $body); |
545 | $cnt = count($body_ary) ; |
546 | $body = ''; |
547 | for ($i=0; $i < $cnt; $i++) { |
548 | if (!ereg("^[>\\s]*$", $body_ary[$i]) || !$body_ary[$i]) { |
549 | sqWordWrap($body_ary[$i], $editor_size ); |
550 | $body .= $body_ary[$i] . "\n"; |
551 | } |
552 | unset($body_ary[$i]); |
553 | } |
554 | sqUnWordWrap($body); |
a43e4b90 |
555 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
a61878d0 |
556 | break; |
a45887d7 |
557 | case ('edit_as_new'): |
c3d1d2cf |
558 | $send_to = decodeHeader($orig_header->getAddr_s('to')); |
559 | $send_to_cc = decodeHeader($orig_header->getAddr_s('cc')); |
560 | $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc')); |
a61878d0 |
561 | $subject = decodeHeader($orig_header->subject); |
562 | $mailprio = $orig_header->priority; |
563 | $orig_from = ''; |
a43e4b90 |
564 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
a61878d0 |
565 | sqUnWordWrap($body); |
566 | break; |
567 | case ('forward'): |
568 | $send_to = ''; |
569 | $subject = decodeHeader($orig_header->subject); |
570 | if ((substr(strtolower($subject), 0, 4) != 'fwd:') && |
571 | (substr(strtolower($subject), 0, 5) != '[fwd:') && |
572 | (substr(strtolower($subject), 0, 6) != '[ fwd:')) { |
573 | $subject = '[Fwd: ' . $subject . ']'; |
574 | } |
575 | $body = getforwardHeader($orig_header) . $body; |
576 | sqUnWordWrap($body); |
a43e4b90 |
577 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
a61878d0 |
578 | break; |
579 | case ('forward_as_attachment'): |
a43e4b90 |
580 | $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); |
a61878d0 |
581 | $body = ''; |
582 | break; |
a45887d7 |
583 | case ('reply_all'): |
a61878d0 |
584 | $send_to_cc = replyAllString($orig_header); |
585 | case ('reply'): |
586 | $send_to = $orig_header->reply_to; |
587 | if (is_object($send_to)) { |
c3d1d2cf |
588 | $send_to = decodeHeader($send_to->getAddr_s('reply_to')); |
a61878d0 |
589 | } else { |
c3d1d2cf |
590 | $send_to = decodeHeader($orig_header->getAddr_s('from')); |
a61878d0 |
591 | } |
592 | $subject = decodeHeader($orig_header->subject); |
593 | $subject = str_replace('"', "'", $subject); |
594 | $subject = trim($subject); |
595 | if (substr(strtolower($subject), 0, 3) != 're:') { |
596 | $subject = 'Re: ' . $subject; |
597 | } |
598 | /* this corrects some wrapping/quoting problems on replies */ |
599 | $rewrap_body = explode("\n", $body); |
600 | |
601 | $body = getReplyCitation($orig_header->from->personal); |
602 | $cnt = count($rewrap_body); |
603 | for ($i=0;$i<$cnt;$i++) { |
604 | // sqWordWrap($rewrap_body[$i], ($editor_size - 2)); |
605 | if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) { |
606 | $gt = $matches[1]; |
607 | $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n"; |
608 | } else { |
609 | $body .= '> ' . $rewrap_body[$i] . "\n"; |
610 | } |
611 | unset($rewrap_body[$i]); |
612 | } |
a43e4b90 |
613 | $composeMessage->reply_rfc822_header = $orig_header; |
a61878d0 |
614 | break; |
615 | default: |
616 | break; |
41b94d65 |
617 | } |
a43e4b90 |
618 | $compose_messages[$session] = $composeMessage; |
619 | sqsession_register($compose_messages, 'compose_messages'); |
620 | |
a61878d0 |
621 | sqimap_logout($imapConnection); |
41b94d65 |
622 | } |
a61878d0 |
623 | $ret = array( 'send_to' => $send_to, |
624 | 'send_to_cc' => $send_to_cc, |
625 | 'send_to_bcc' => $send_to_bcc, |
626 | 'subject' => $subject, |
627 | 'mailprio' => $mailprio, |
628 | 'body' => $body, |
629 | 'identity' => $identity ); |
630 | |
41b94d65 |
631 | return ($ret); |
48985d59 |
632 | } /* function newMail() */ |
633 | |
a43e4b90 |
634 | function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) { |
59edcad6 |
635 | global $attachment_dir, $username, $data_dir, $squirrelmail_language; |
48985d59 |
636 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
41b94d65 |
637 | if (!count($message->entities) || |
638 | ($message->type0 == 'message' && $message->type1 == 'rfc822')) { |
639 | if ( !in_array($message->entity_id, $entities) && $message->entity_id) { |
a43e4b90 |
640 | switch ($message->type0) { |
641 | case 'message': |
642 | if ($message->type1 == 'rfc822') { |
643 | $filename = decodeHeader($message->rfc822_header->subject.'.eml'); |
644 | if ($filename == "") { |
645 | $filename = "untitled-".$message->entity_id.'.eml'; |
646 | } |
647 | } else { |
648 | $filename = decodeHeader($message->getFilename()); |
649 | } |
650 | break; |
651 | default: |
652 | $filename = decodeHeader($message->getFilename()); |
653 | break; |
654 | } |
655 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
656 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
657 | $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename); |
658 | } |
659 | |
660 | $localfilename = GenerateRandomString(32, '', 7); |
661 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
662 | while (file_exists($full_localfilename)) { |
663 | $localfilename = GenerateRandomString(32, '', 7); |
664 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
665 | } |
666 | $message->att_local_name = $full_localfilename; |
667 | if (!$message->mime_header) { /* temporary hack */ |
668 | $message->mime_header = $message->header; |
669 | } |
670 | |
671 | $composeMessage->addEntity($message); |
672 | |
673 | /* Write Attachment to file */ |
674 | $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb'); |
675 | fputs($fp, decodeBody(mime_fetch_body($imapConnection, |
676 | $passed_id, $message->entity_id), |
677 | $message->header->encoding)); |
678 | fclose ($fp); |
48985d59 |
679 | } |
734f4ee6 |
680 | } else { |
a43e4b90 |
681 | for ($i=0, $entCount=count($message->entities); $i<$entCount;$i++) { |
682 | $composeMessage=getAttachments($message->entities[$i], $composeMessage, $passed_id, $entities, $imapConnection); |
48985d59 |
683 | } |
684 | } |
a43e4b90 |
685 | // setPref($data_dir, $username, 'attachments', serialize($attachments)); |
686 | return $composeMessage; |
48985d59 |
687 | } |
688 | |
a43e4b90 |
689 | function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, |
756406df |
690 | $passed_ent_id='', $imapConnection) { |
a6ec592e |
691 | global $attachments, $attachment_dir, $username, $data_dir, $uid_support; |
692 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
756406df |
693 | if (!$passed_ent_id) { |
a61878d0 |
694 | $body_a = sqimap_run_command($imapConnection, |
695 | 'FETCH '.$passed_id.' RFC822', |
696 | TRUE, $response, $readmessage, |
697 | $uid_support); |
756406df |
698 | } else { |
699 | $body_a = sqimap_run_command($imapConnection, |
a61878d0 |
700 | 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']', |
701 | TRUE, $response, $readmessage, $uid_support); |
702 | $message = $message->parent; |
756406df |
703 | } |
a6ec592e |
704 | if ($response = 'OK') { |
a61878d0 |
705 | $subject = encodeHeader($message->rfc822_header->subject); |
706 | array_shift($body_a); |
707 | $body = implode('', $body_a) . "\r\n"; |
708 | |
709 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
710 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
711 | |
a43e4b90 |
712 | $fp = fopen( $full_localfilename, 'w'); |
a61878d0 |
713 | fwrite ($fp, $body); |
714 | fclose($fp); |
a43e4b90 |
715 | $composeMessage->initAttachment('message/rfc822',$subject.'.eml', |
716 | $full_localfilename); |
717 | } |
718 | return $composeMessage; |
a6ec592e |
719 | } |
720 | |
41b94d65 |
721 | function showInputForm ($session, $values=false) { |
722 | global $send_to, $send_to_cc, $body, |
48985d59 |
723 | $passed_body, $color, $use_signature, $signature, $prefix_sig, |
724 | $editor_size, $attachments, $subject, $newmail, |
41b94d65 |
725 | $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox, |
48985d59 |
726 | $from_htmladdr_search, $location_of_buttons, $attachment_dir, |
727 | $username, $data_dir, $identity, $draft_id, $delete_draft, |
9c3e6cd4 |
728 | $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win, |
44560457 |
729 | $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action, |
a43e4b90 |
730 | $username, $compose_messages; |
731 | |
732 | $composeMessage = $compose_messages[$session]; |
48985d59 |
733 | |
3b487216 |
734 | $subject = decodeHeader($subject, false); |
41b94d65 |
735 | if ($values) { |
736 | $send_to = $values['send_to']; |
737 | $send_to_cc = $values['send_to_cc']; |
738 | $send_to_bcc = $values['send_to_bcc']; |
739 | $subject = $values['subject']; |
740 | $mailprio = $values['mailprio']; |
741 | $body = $values['body']; |
bdb92db3 |
742 | $identity = $values['identity']; |
41b94d65 |
743 | } |
744 | |
48985d59 |
745 | if ($use_javascript_addr_book) { |
746 | echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" . |
747 | 'function open_abook() { ' . "\n" . |
748 | ' var nwin = window.open("addrbook_popup.php","abookpopup",' . |
749 | '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" . |
750 | ' if((!nwin.opener) && (document.windows != null))' . "\n" . |
751 | ' nwin.opener = document.windows;' . "\n" . |
752 | "}\n" . |
753 | '// --></SCRIPT>' . "\n\n"; |
754 | } |
755 | |
41b94d65 |
756 | echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' . |
757 | 'ENCTYPE="multipart/form-data"'; |
48985d59 |
758 | do_hook("compose_form"); |
e02775fe |
759 | |
57257333 |
760 | |
48985d59 |
761 | echo ">\n"; |
762 | |
41b94d65 |
763 | if ($action == 'draft') { |
764 | echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n"; |
48985d59 |
765 | } |
766 | if (isset($delete_draft)) { |
767 | echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n"; |
768 | } |
da95c4b6 |
769 | if (isset($session)) { |
44560457 |
770 | echo '<input type="hidden" name="session" value="' . $session . "\">\n"; |
da95c4b6 |
771 | } |
08bad2b1 |
772 | |
773 | if (isset($passed_id)) { |
774 | echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n"; |
775 | } |
44560457 |
776 | |
9c3e6cd4 |
777 | if ($saved_draft == 'yes') { |
778 | echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>'; |
779 | } |
780 | if ($mail_sent == 'yes') { |
781 | echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>'; |
782 | } |
6206f6c4 |
783 | echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n"; |
9c3e6cd4 |
784 | if ($compose_new_win == '1') { |
a61878d0 |
785 | echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" . |
786 | ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n"; |
9c3e6cd4 |
787 | } |
78a35fcd |
788 | if ($location_of_buttons == 'top') { |
789 | showComposeButtonRow(); |
790 | } |
48985d59 |
791 | |
715225af |
792 | $idents = getPref($data_dir, $username, 'identities', 0); |
793 | if ($idents > 1) { |
41b94d65 |
794 | echo ' <TR>' . "\n" . |
795 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . |
796 | "\n" . |
797 | _("From:") . |
798 | ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
48985d59 |
799 | '<select name=identity>' . "\n" . |
800 | '<option value=default>' . |
801 | htmlspecialchars(getPref($data_dir, $username, 'full_name')); |
802 | $em = getPref($data_dir, $username, 'email_address'); |
803 | if ($em != '') { |
248bfebb |
804 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
48985d59 |
805 | } |
806 | for ($i = 1; $i < $idents; $i ++) { |
248bfebb |
807 | echo '<option value="' . $i . '"'; |
48985d59 |
808 | if (isset($identity) && $identity == $i) { |
78a35fcd |
809 | echo ' SELECTED'; |
48985d59 |
810 | } |
811 | echo '>' . htmlspecialchars(getPref($data_dir, $username, |
812 | 'full_name' . $i)); |
248bfebb |
813 | $em = getPref($data_dir, $username, 'email_address' . $i); |
48985d59 |
814 | if ($em != '') { |
78a35fcd |
815 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
48985d59 |
816 | } |
9f599fe3 |
817 | echo '</option>'; |
48985d59 |
818 | } |
819 | echo '</select>' . "\n" . |
41b94d65 |
820 | ' </TD>' . "\n" . |
821 | ' </TR>' . "\n"; |
822 | } |
823 | echo ' <TR>' . "\n" . |
824 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" . |
825 | _("To:") . |
826 | ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
827 | ' <INPUT TYPE=text NAME="send_to" VALUE="' . |
828 | htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" . |
829 | ' </TD>' . "\n" . |
830 | ' </TR>' . "\n" . |
831 | ' <TR>' . "\n" . |
832 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
833 | _("CC:") . |
834 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
835 | ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' . |
836 | htmlspecialchars($send_to_cc) . '"><BR>' . "\n" . |
837 | ' </TD>' . "\n" . |
838 | ' </TR>' . "\n" . |
839 | ' <TR>' . "\n" . |
840 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
841 | _("BCC:") . |
842 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
843 | ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' . |
844 | htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" . |
845 | '</TD></TR>' . "\n" . |
846 | ' <TR>' . "\n" . |
847 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
848 | _("Subject:") . |
849 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n"; |
850 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
851 | htmlspecialchars($subject) . '">'; |
852 | echo '</td></tr>' . "\n\n"; |
48985d59 |
853 | |
78a35fcd |
854 | if ($location_of_buttons == 'between') { |
855 | showComposeButtonRow(); |
856 | } |
fdc83c55 |
857 | if ($compose_new_win == '1') { |
41b94d65 |
858 | echo ' <TR>' . "\n" . |
859 | ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" . |
860 | ' <TEXTAREA NAME=body ROWS=20 COLS="' . |
861 | $editor_size . '" WRAP="VIRTUAL">'; |
fdc83c55 |
862 | } |
863 | else { |
41b94d65 |
864 | echo ' <TR>' . "\n" . |
865 | ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" . |
866 | ' <TEXTAREA NAME=body ROWS=20 COLS="' . |
867 | $editor_size . '" WRAP="VIRTUAL">'; |
fdc83c55 |
868 | } |
48985d59 |
869 | if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) { |
3b17e952 |
870 | if ($sig_first == '1') { |
83be314a |
871 | if ($charset == 'iso-2022-jp') { |
872 | echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); |
873 | } else { |
3b17e952 |
874 | echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); |
83be314a |
875 | } |
3b17e952 |
876 | echo "\n\n".htmlspecialchars($body); |
877 | } |
878 | else { |
879 | echo "\n\n".htmlspecialchars($body); |
83be314a |
880 | if ($charset == 'iso-2022-jp') { |
881 | echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); |
882 | }else{ |
3b17e952 |
883 | echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); |
884 | } |
885 | } |
83be314a |
886 | } |
3b17e952 |
887 | else { |
888 | echo htmlspecialchars($body); |
48985d59 |
889 | } |
41b94d65 |
890 | echo '</TEXTAREA><BR>' . "\n" . |
891 | ' </TD>' . "\n" . |
892 | ' </TR>' . "\n"; |
48985d59 |
893 | |
894 | if ($location_of_buttons == 'bottom') { |
895 | showComposeButtonRow(); |
896 | } else { |
a61878d0 |
897 | echo ' <TR><TD COLSPAN=2 ALIGN=RIGHT>' . |
898 | ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' . |
899 | ' <BR><BR>' . |
900 | ' </TD></TR>' . "\n"; |
48985d59 |
901 | } |
46bb8da8 |
902 | |
48985d59 |
903 | /* This code is for attachments */ |
a61878d0 |
904 | echo '<table width="100%" cellpadding="0" cellspacing="4" align="center" border="0">' . |
905 | ' <tr><td>' . |
906 | ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">' . |
907 | ' <tr><td>' . |
908 | ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">' . |
909 | ' <TR>' . "\n" . |
41b94d65 |
910 | ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" . |
911 | _("Attach:") . |
912 | ' </TD>' . "\n" . |
913 | ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" . |
914 | ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" . |
915 | ' <input type="submit" name="attach"' . |
916 | ' value="' . _("Add") .'">' . "\n" . |
917 | ' </TD>' . "\n" . |
918 | ' </TR>' . "\n"; |
91f2085b |
919 | |
41b94d65 |
920 | |
91f2085b |
921 | $s_a = array(); |
a43e4b90 |
922 | foreach ($composeMessage->entities as $key => $attachment) { |
923 | $attached_file = $attachment->att_local_name; |
924 | if ($attachment->att_local_name || $attachment->body_part) { |
925 | $attached_filename = decodeHeader($attachment->mime_header->getParameter('name')); |
926 | $type = $attachment->mime_header->type0.'/'. |
927 | $attachment->mime_header->type1; |
928 | $s_a[] = '<input type="checkbox" name="delete[]" value="' . |
929 | $key . "\">\n" . $attached_filename . ' - ' . $type . |
930 | ' ('.show_readable_size( filesize( $attached_file ) ) |
931 | . ')<br>'."\n"; |
932 | } |
91f2085b |
933 | } |
934 | if (count($s_a)) { |
935 | foreach ($s_a as $s) { |
936 | echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>'; |
a61878d0 |
937 | } |
91f2085b |
938 | echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' . |
939 | _("Delete selected attachments") . "\">\n" . |
940 | '</td></tr>'; |
941 | } |
a61878d0 |
942 | echo ' </table></td></tr>' . |
943 | ' </table>' . |
944 | ' </td></tr>'; |
41b94d65 |
945 | |
41b94d65 |
946 | /* End of attachment code */ |
07687736 |
947 | if ($compose_new_win == '1') { |
41b94d65 |
948 | echo '</TABLE>'."\n"; |
07687736 |
949 | } |
a61878d0 |
950 | echo '</TABLE>' . "\n" . |
951 | '<input type="hidden" name="username" value="'. $username . "\">\n" . |
952 | '<input type=hidden name=action value=' . $action . ">\n" . |
953 | '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) . |
48985d59 |
954 | "\">\n" . |
955 | '</FORM>'; |
9f599fe3 |
956 | do_hook('compose_bottom'); |
48985d59 |
957 | echo '</BODY></HTML>' . "\n"; |
958 | } |
959 | |
960 | |
70c4fd84 |
961 | function showComposeButtonRow() { |
78a35fcd |
962 | global $use_javascript_addr_book, $save_as_draft, |
a61878d0 |
963 | $default_use_priority, $mailprio, $default_use_mdn, |
964 | $request_mdn, $request_dr, |
965 | $data_dir, $username; |
70c4fd84 |
966 | |
41b94d65 |
967 | echo " <TR><TD>\n</TD><TD>\n"; |
ae25968c |
968 | if ($default_use_priority) { |
969 | if(!isset($mailprio)) { |
970 | $mailprio = "3"; |
70c4fd84 |
971 | } |
972 | echo _("Priority") .': <select name="mailprio">'. |
973 | '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'. |
974 | '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'. |
975 | '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'. |
976 | "</select>"; |
ae25968c |
977 | } |
978 | $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn); |
979 | if ($default_use_mdn) { |
70c4fd84 |
980 | if ($mdn_user_support) { |
981 | echo "\n\t". _("Receipt") .': '. |
b2a7e5bc |
982 | '<input type="checkbox" name="request_mdn" value=1'. |
a61878d0 |
983 | ($request_mdn=='1'?' checked':'') .'>'. _("On Read"). |
b2a7e5bc |
984 | ' <input type="checkbox" name="request_dr" value=1'. |
a61878d0 |
985 | ($request_dr=='1'?' checked':'') .'>'. _("On Delivery"); |
70c4fd84 |
986 | } |
ae25968c |
987 | } |
48985d59 |
988 | |
a61878d0 |
989 | echo " </td></tr>\n <TR><td>\n </td><td>\n" . |
990 | "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n"; |
78a35fcd |
991 | if ($use_javascript_addr_book) { |
46bb8da8 |
992 | echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"". |
993 | " <input type=button value=\\\""._("Addresses"). |
994 | "\\\" onclick='javascript:open_abook();'>\");". |
995 | " // --></SCRIPT><NOSCRIPT>\n". |
996 | " <input type=submit name=\"html_addr_search\" value=\"". |
997 | _("Addresses")."\">". |
998 | " </NOSCRIPT>\n"; |
734f4ee6 |
999 | } else { |
78a35fcd |
1000 | echo " <input type=submit name=\"html_addr_search\" value=\"". |
1001 | _("Addresses")."\">"; |
1002 | } |
48985d59 |
1003 | |
78a35fcd |
1004 | if ($save_as_draft) { |
1005 | echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n"; |
1006 | } |
0a17f9dd |
1007 | |
6206f6c4 |
1008 | echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n"; |
78a35fcd |
1009 | do_hook('compose_button_row'); |
441f2d33 |
1010 | |
41b94d65 |
1011 | echo " </TD></TR>\n\n"; |
78a35fcd |
1012 | } |
b278172f |
1013 | |
70c4fd84 |
1014 | function checkInput ($show) { |
78a35fcd |
1015 | /* |
1016 | * I implemented the $show variable because the error messages |
1017 | * were getting sent before the page header. So, I check once |
1018 | * using $show=false, and then when i'm ready to display the error |
1019 | * message, show=true |
1020 | */ |
6bf2a88f |
1021 | global $body, $send_to, $send_to_bcc, $subject, $color; |
78a35fcd |
1022 | |
6bf2a88f |
1023 | if ($send_to == '' && $send_to_bcc == '') { |
78a35fcd |
1024 | if ($show) { |
0ad7dbda |
1025 | plain_error_message(_("You have not filled in the \"To:\" field."), $color); |
78a35fcd |
1026 | } |
1027 | return false; |
1028 | } |
1029 | return true; |
1030 | } /* function checkInput() */ |
df15de21 |
1031 | |
3806fa52 |
1032 | |
00793a25 |
1033 | /* True if FAILURE */ |
da95c4b6 |
1034 | function saveAttachedFiles($session) { |
3f6b1b6f |
1035 | global $HTTP_POST_FILES, $attachment_dir, $attachments, $username, |
a43e4b90 |
1036 | $data_dir, $compose_messages; |
4c9d2242 |
1037 | |
1038 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
1039 | $localfilename = GenerateRandomString(32, '', 7); |
1040 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
1041 | while (file_exists($full_localfilename)) { |
1042 | $localfilename = GenerateRandomString(32, '', 7); |
1043 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
1044 | } |
1045 | |
1046 | if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
a43e4b90 |
1047 | if (function_exists("move_uploaded_file")) { |
a61878d0 |
1048 | if (!@move_uploaded_file($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
a43e4b90 |
1049 | return true; |
1050 | } |
1051 | } else { |
1052 | if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
a61878d0 |
1053 | return true; |
1054 | } |
a43e4b90 |
1055 | } |
a61878d0 |
1056 | } |
a43e4b90 |
1057 | $message = $compose_messages[$session]; |
1058 | $type = strtolower($HTTP_POST_FILES['attachfile']['type']); |
1059 | $name = $HTTP_POST_FILES['attachfile']['name']; |
1060 | $message->initAttachment($type, $name, $full_localfilename); |
1061 | $compose_messages[$session] = $message; |
4c9d2242 |
1062 | } |
1063 | |
a43e4b90 |
1064 | function ClearAttachments($composeMessage) { |
b48d3c53 |
1065 | if ($composeMessage->att_local_name) { |
1066 | $attached_file = $composeMessage->att_local_name; |
a43e4b90 |
1067 | if (file_exists($attached_file)) { |
1068 | unlink($attached_file); |
8712abea |
1069 | } |
da95c4b6 |
1070 | } |
a43e4b90 |
1071 | for ($i=0, $entCount=count($composeMessage->entities);$i< $entCount; ++$i) { |
1072 | ClearAttachments($composeMessage->entities[$i]); |
1073 | } |
4c9d2242 |
1074 | } |
1075 | |
da95c4b6 |
1076 | |
a43e4b90 |
1077 | |
1078 | function getReplyCitation($orig_from) { |
4c9d2242 |
1079 | global $reply_citation_style, $reply_citation_start, $reply_citation_end; |
1080 | |
1081 | /* First, return an empty string when no citation style selected. */ |
1082 | if (($reply_citation_style == '') || ($reply_citation_style == 'none')) { |
1083 | return ''; |
1084 | } |
1085 | |
4c9d2242 |
1086 | /* Make sure our final value isn't an empty string. */ |
1087 | if ($orig_from == '') { |
1088 | return ''; |
1089 | } |
1090 | |
1091 | /* Otherwise, try to select the desired citation style. */ |
1092 | switch ($reply_citation_style) { |
1093 | case 'author_said': |
1094 | $start = ''; |
1095 | $end = ' ' . _("said") . ':'; |
1096 | break; |
1097 | case 'quote_who': |
1098 | $start = '<' . _("quote") . ' ' . _("who") . '="'; |
1099 | $end = '">'; |
1100 | break; |
1101 | case 'user-defined': |
55b321f2 |
1102 | $start = $reply_citation_start . |
a61878d0 |
1103 | ($reply_citation_start == '' ? '' : ' '); |
4c9d2242 |
1104 | $end = $reply_citation_end; |
1105 | break; |
1106 | default: |
1107 | return ''; |
1108 | } |
1109 | |
1110 | /* Build and return the citation string. */ |
1111 | return ($start . $orig_from . $end . "\n"); |
1112 | } |
1113 | |
a43e4b90 |
1114 | /* temporary function to make use of the deliver class. |
1115 | In the future the responsable backend should be automaticly loaded |
1116 | and conf.pl should show a list of available backends. |
1117 | The message also should be constructed by the message class. |
1118 | */ |
1119 | |
b48d3c53 |
1120 | function sendMessage($composeMessage, $draft=false) { |
a43e4b90 |
1121 | global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body, |
1122 | $username, $popuser, $usernamedata, $identity, $data_dir, |
1123 | $request_mdn, $request_dr, $default_charset, $color, $useSendmail, |
b48d3c53 |
1124 | $domain, $action; |
a43e4b90 |
1125 | global $imapServerAddress, $imapPort, $sent_folder, $key; |
1126 | |
1127 | $rfc822_header = $composeMessage->rfc822_header; |
1128 | $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain); |
1129 | $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain); |
1130 | $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain); |
1131 | $rfc822_header->priority = $mailprio; |
1132 | $rfc822_header->subject = $subject; |
1133 | $special_encoding=''; |
1134 | if (strtolower($default_charset) == 'iso-2022-jp') { |
1135 | if (mb_detect_encoding($body) == 'ASCII') { |
1136 | $special_encoding = '8bit'; |
1137 | } else { |
1138 | $body = mb_convert_encoding($body, 'JIS'); |
1139 | $special_encoding = '7bit'; |
1140 | } |
1141 | } |
1142 | $composeMessage->setBody($body); |
1143 | |
1144 | if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) { |
1145 | $popuser = $usernamedata[1]; |
1146 | $domain = $usernamedata[2]; |
1147 | unset($usernamedata); |
1148 | } else { |
1149 | $popuser = $username; |
1150 | } |
1151 | $reply_to = ''; |
1152 | if (isset($identity) && $identity != 'default') { |
045714fd |
1153 | $from_mail = getPref($data_dir, $username,'email_address' . $identity); |
1154 | $full_name = getPref($data_dir, $username,'full_name' . $identity); |
1155 | $reply_to = getPref($data_dir, $username,'reply_to' . $identity); |
a43e4b90 |
1156 | } else { |
1157 | $from_mail = getPref($data_dir, $username, 'email_address'); |
1158 | $full_name = getPref($data_dir, $username, 'full_name'); |
a43e4b90 |
1159 | $reply_to = getPref($data_dir, $username,'reply_to'); |
1160 | } |
045714fd |
1161 | if (!$from_mail) { |
1162 | $from_mail = "$popuser@$domain"; |
1163 | $full_name = ''; |
1164 | } |
1165 | $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true); |
1166 | if ($full_name) { |
9783f396 |
1167 | $from = $rfc822_header->from[0]; |
045714fd |
1168 | if (!$from->host) $from->host = $domain; |
1169 | $from_addr = $full_name .' <'.$from->mailbox.'@'.$from->host.'>'; |
1170 | $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); |
a43e4b90 |
1171 | } |
a43e4b90 |
1172 | if ($reply_to) { |
1173 | $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); |
1174 | } |
1175 | /* Receipt: On Read */ |
1176 | if (isset($request_mdn) && $request_mdn) { |
1177 | $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true); |
1178 | } |
1179 | /* Receipt: On Delivery */ |
1180 | if (isset($request_dr) && $request_dr) { |
1181 | $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail; |
1182 | } |
1183 | /* multipart messages */ |
1184 | if (count($composeMessage->entities)) { |
1185 | $message_body = new Message(); |
1186 | $message_body->body_part = $composeMessage->body_part; |
1187 | $composeMessage->body_part = ''; |
1188 | $mime_header = new MessageHeader; |
1189 | $mime_header->type0 = 'text'; |
1190 | $mime_header->type1 = 'plain'; |
1191 | if ($special_encoding) { |
1192 | $mime_header->encoding = $special_encoding; |
1193 | } else { |
1194 | $mime_header->encoding = 'us-ascii'; |
1195 | } |
1196 | if ($default_charset) { |
1197 | $mime_header->parameters['charset'] = $default_charset; |
1198 | } |
1199 | $message_body->mime_header = $mime_header; |
1200 | array_unshift($composeMessage->entities, $message_body); |
1201 | $content_type = new ContentType('multipart/mixed'); |
1202 | } else { |
1203 | $content_type = new ContentType('text/plain'); |
1204 | } |
1205 | if ($default_charset) { |
1206 | $content_type->properties['charset']=$default_charset; |
1207 | } |
1208 | |
1209 | $rfc822_header->content_type = $content_type; |
1210 | $composeMessage->rfc822_header = $rfc822_header; |
1211 | |
b48d3c53 |
1212 | if (!$useSendmail && !$draft) { |
86725763 |
1213 | require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); |
a43e4b90 |
1214 | $deliver = new Deliver_SMTP(); |
1215 | global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp; |
1216 | if ($use_authenticated_smtp) { |
1217 | global $key, $onetimepad; |
1218 | $user = $username; |
1219 | $pass = OneTimePadDecrypt($key, $onetimepad); |
1220 | } else { |
1221 | $user = ''; |
1222 | $pass = ''; |
1223 | } |
b48d3c53 |
1224 | $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; |
a43e4b90 |
1225 | $stream = $deliver->initStream($composeMessage,$domain,0, |
1226 | $smtpServerAddress, $smtpPort, $authPop); |
b48d3c53 |
1227 | } elseif (!$draft) { |
86725763 |
1228 | require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); |
b48d3c53 |
1229 | global $sendmail_path; |
1230 | $deliver = new Deliver_SendMail(); |
1231 | $stream = $deliver->initStream($composeMessage,$sendmail_path); |
1232 | } elseif ($draft) { |
1233 | global $draft_folder; |
86725763 |
1234 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
b48d3c53 |
1235 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, |
1236 | $imapPort, 0); |
1237 | if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) { |
86725763 |
1238 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
b48d3c53 |
1239 | $imap_deliver = new Deliver_IMAP(); |
1240 | $length = $imap_deliver->mail($composeMessage); |
1241 | sqimap_append ($imap_stream, $draft_folder, $length); |
1242 | $imap_deliver->mail($composeMessage, $imap_stream); |
1243 | sqimap_append_done ($imap_stream); |
1244 | sqimap_logout($imap_stream); |
1245 | unset ($imap_deliver); |
1246 | |
1247 | } |
1248 | return $length; |
a43e4b90 |
1249 | } |
1250 | $succes = false; |
1251 | if ($stream) { |
1252 | $length = $deliver->mail($composeMessage, $stream); |
1253 | $succes = $deliver->finalizeStream($stream); |
1254 | } |
1255 | if (!$succes) { |
1256 | $msg = $deliver->dlv_msg . '<br>Server replied: '.$deliver->dlv_ret_nr; |
1257 | plain_error_message($msg, $color); |
1258 | } else { |
1259 | unset ($deliver); |
1260 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, |
1261 | $imapPort, 0); |
1262 | if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) { |
1263 | sqimap_append ($imap_stream, $sent_folder, $length); |
86725763 |
1264 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
a43e4b90 |
1265 | $imap_deliver = new Deliver_IMAP(); |
1266 | $imap_deliver->mail($composeMessage, $imap_stream); |
1267 | sqimap_append_done ($imap_stream); |
a43e4b90 |
1268 | unset ($imap_deliver); |
1269 | } |
b48d3c53 |
1270 | global $passed_id, $mailbox, $action; |
a43e4b90 |
1271 | ClearAttachments($composeMessage); |
b48d3c53 |
1272 | if ($action == 'reply' || $action == 'reply_all') { |
1273 | sqimap_mailbox_select ($imap_stream, $mailbox); |
1274 | sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true); |
1275 | } |
1276 | sqimap_logout($imap_stream); |
a43e4b90 |
1277 | } |
1278 | return $succes; |
1279 | } |
1280 | |
6bf2a88f |
1281 | ?> |