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 | |
35586184 |
20 | require_once('../src/validate.php'); |
21 | require_once('../functions/imap.php'); |
22 | require_once('../functions/date.php'); |
23 | require_once('../functions/mime.php'); |
24 | require_once('../functions/smtp.php'); |
25 | require_once('../functions/display_messages.php'); |
26 | require_once('../functions/plugin.php'); |
8467bf00 |
27 | |
48985d59 |
28 | if (!isset($attachments)) { |
29 | $attachments = array(); |
30 | session_register('attachments'); |
31 | } |
32 | |
00793a25 |
33 | if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) { |
34 | $mailbox = 'INBOX'; |
35 | } |
36 | |
37 | if (isset($draft)) { |
715225af |
38 | include_once ('../src/draft_actions.php'); |
57257333 |
39 | if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $MDN)) { |
00793a25 |
40 | showInputForm(); |
41 | exit(); |
734f4ee6 |
42 | } else { |
00793a25 |
43 | $draft_message = _("Draft Email Saved"); |
44 | /* If this is a resumed draft, then delete the original */ |
45 | if(isset($delete_draft)) { |
46 | Header("Location: delete_message.php?mailbox=$draft_folder". |
47 | "&message=$delete_draft&sort=$sort&startMessage=1"); |
48 | exit(); |
734f4ee6 |
49 | } else { |
00793a25 |
50 | Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort". |
51 | "&startMessage=1¬e=$draft_message"); |
52 | exit(); |
53 | } |
54 | } |
55 | } |
56 | |
57 | if (isset($send)) { |
58 | if (isset($HTTP_POST_FILES['attachfile']) && |
59 | $HTTP_POST_FILES['attachfile']['tmp_name'] && |
60 | $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { |
61 | $AttachFailure = saveAttachedFiles(); |
62 | } |
63 | if (checkInput(false) && !isset($AttachFailure)) { |
64 | $urlMailbox = urlencode (trim($mailbox)); |
65 | if (! isset($reply_id)) { |
66 | $reply_id = 0; |
67 | } |
68 | /* |
69 | * Set $default_charset to correspond with the user's selection |
70 | * of language interface. |
71 | */ |
72 | set_my_charset(); |
73 | |
74 | /* |
75 | * This is to change all newlines to \n |
76 | * We'll change them to \r\n later (in the sendMessage function) |
77 | */ |
78 | $body = str_replace("\r\n", "\n", $body); |
79 | $body = str_replace("\r", "\n", $body); |
80 | |
81 | /* |
82 | * Rewrap $body so that no line is bigger than $editor_size |
83 | * This should only really kick in the sqWordWrap function |
84 | * if the browser doesn't support "HARD" as the wrap type |
85 | * Or, in Opera's case, something goes wrong. |
86 | */ |
87 | $body = explode("\n", $body); |
88 | $newBody = ''; |
89 | foreach ($body as $line) { |
90 | if( $line <> '-- ' ) { |
91 | $line = rtrim($line); |
92 | } |
93 | if (strlen($line) <= $editor_size + 1) { |
94 | $newBody .= $line . "\n"; |
734f4ee6 |
95 | } else { |
00793a25 |
96 | sqWordWrap($line, $editor_size) . "\n"; |
97 | $newBody .= $line; |
98 | } |
99 | } |
100 | $body = $newBody; |
101 | |
102 | do_hook("compose_send"); |
57257333 |
103 | |
104 | $MDN = False; // we are not sending a mdn response |
00793a25 |
105 | if (! isset($mailprio)) { |
106 | $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, |
57257333 |
107 | $subject, $body, $reply_id, $MDN); |
734f4ee6 |
108 | } else { |
00793a25 |
109 | $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, |
57257333 |
110 | $subject, $body, $reply_id, $MDN, $mailprio); |
00793a25 |
111 | } |
112 | if (! $Result) { |
113 | showInputForm(); |
114 | exit(); |
115 | } |
116 | if ( isset($delete_draft)) { |
117 | Header("Location: delete_message.php?mailbox=$draft_folder". |
118 | "&message=$delete_draft&sort=$sort&startMessage=1"); |
119 | exit(); |
120 | } |
121 | |
122 | Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort". |
123 | "&startMessage=1"); |
734f4ee6 |
124 | } else { |
00793a25 |
125 | /* |
126 | *$imapConnection = sqimap_login($username, $key, $imapServerAddress, |
127 | * $imapPort, 0); |
128 | */ |
129 | displayPageHeader($color, $mailbox); |
130 | |
131 | if (isset($AttachFailure)) { |
132 | plain_error_message(_("Could not move/copy file. File not attached"), |
133 | $color); |
134 | } |
135 | |
136 | checkInput(true); |
137 | showInputForm(); |
138 | /* sqimap_logout($imapConnection); */ |
139 | } |
140 | } |
141 | elseif (isset($html_addr_search_done)) { |
142 | displayPageHeader($color, $mailbox); |
143 | |
144 | if (isset($send_to_search) && is_array($send_to_search)) { |
145 | foreach ($send_to_search as $k => $v) { |
146 | if (substr($k, 0, 1) == 'T') { |
147 | if ($send_to) { |
148 | $send_to .= ', '; |
149 | } |
150 | $send_to .= $v; |
151 | } |
152 | elseif (substr($k, 0, 1) == 'C') { |
153 | if ($send_to_cc) { |
154 | $send_to_cc .= ', '; |
155 | } |
156 | $send_to_cc .= $v; |
157 | } |
158 | elseif (substr($k, 0, 1) == 'B') { |
159 | if ($send_to_bcc) { |
160 | $send_to_bcc .= ', '; |
161 | } |
162 | $send_to_bcc .= $v; |
163 | } |
164 | } |
165 | } |
166 | showInputForm(); |
167 | } |
168 | elseif (isset($html_addr_search)) { |
169 | if (isset($HTTP_POST_FILES['attachfile']) && |
170 | $HTTP_POST_FILES['attachfile']['tmp_name'] && |
171 | $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { |
172 | if (saveAttachedFiles()) { |
173 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
174 | } |
175 | } |
176 | /* |
177 | * I am using an include so as to elminiate an extra unnecessary |
178 | * click. If you can think of a better way, please implement it. |
179 | */ |
180 | include_once('./addrbook_search_html.php'); |
181 | } |
182 | elseif (isset($attach)) { |
183 | if (saveAttachedFiles()) { |
184 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
185 | } |
186 | displayPageHeader($color, $mailbox); |
187 | showInputForm(); |
188 | } |
189 | elseif (isset($do_delete)) { |
190 | displayPageHeader($color, $mailbox); |
191 | |
192 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
193 | if (isset($delete) && is_array($delete)) { |
194 | foreach($delete as $index) { |
195 | $attached_file = $hashed_attachment_dir . '/' |
196 | . $attachments[$index]['localfilename']; |
197 | unlink ($attached_file); |
198 | unset ($attachments[$index]); |
199 | } |
200 | } |
201 | |
202 | showInputForm(); |
734f4ee6 |
203 | } else { |
00793a25 |
204 | /* |
205 | * This handles the default case as well as the error case |
206 | * (they had the same code) --> if (isset($smtpErrors)) |
207 | */ |
208 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
209 | $imapPort, 0); |
210 | displayPageHeader($color, $mailbox); |
211 | |
212 | $newmail = true; |
213 | |
214 | ClearAttachments(); |
215 | |
216 | if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num) { |
217 | getAttachments(0); |
218 | } |
219 | |
220 | if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num) { |
221 | getAttachments(0); |
222 | } |
223 | |
224 | newMail(); |
225 | showInputForm(); |
226 | sqimap_logout($imapConnection); |
227 | } |
228 | |
229 | exit(); |
230 | |
231 | |
232 | /**************** Only function definitions go below *************/ |
233 | |
234 | |
48985d59 |
235 | /* This function is used when not sending or adding attachments */ |
236 | function newMail () { |
237 | global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body, |
238 | $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size, |
239 | $draft_id, $use_signature; |
240 | |
3b487216 |
241 | $send_to = decodeHeader($send_to, false); |
242 | $send_to_cc = decodeHeader($send_to_cc, false); |
243 | $send_to_bcc = decodeHeader($send_to_bcc, false); |
48985d59 |
244 | |
245 | if ($forward_id) { |
246 | $id = $forward_id; |
247 | } elseif ($reply_id) { |
248 | $id = $reply_id; |
249 | } |
250 | |
251 | if ($draft_id){ |
252 | $id = $draft_id; |
253 | $use_signature = FALSE; |
254 | } |
255 | |
256 | if (isset($id)) { |
257 | sqimap_mailbox_select($imapConnection, $mailbox); |
258 | $message = sqimap_get_message($imapConnection, $id, $mailbox); |
259 | $orig_header = $message->header; |
260 | if ($ent_num) { |
1195c340 |
261 | $message = getEntity($message, $ent_num); |
48985d59 |
262 | } |
263 | if ($message->header->type0 == 'text' || |
264 | $message->header->type1 == 'message') { |
265 | if ($ent_num) { |
266 | $body = decodeBody( |
267 | mime_fetch_body($imapConnection, $id, $ent_num), |
268 | $message->header->encoding); |
269 | } else { |
270 | $body = decodeBody( |
271 | mime_fetch_body($imapConnection, $id, 1), |
272 | $message->header->encoding); |
273 | } |
734f4ee6 |
274 | } else { |
e707c74a |
275 | $body = ''; |
48985d59 |
276 | } |
9487c2ff |
277 | |
e707c74a |
278 | if ($message->header->type1 == 'html') { |
429f8906 |
279 | $body = strip_tags($body); |
48985d59 |
280 | } |
f82d9be2 |
281 | |
48985d59 |
282 | sqUnWordWrap($body); |
283 | $body_ary = explode("\n", $body); |
284 | $i = count($body_ary) - 1; |
285 | while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) { |
fb6ce88e |
286 | unset($body_ary[$i]); |
287 | $i --; |
48985d59 |
288 | } |
289 | $body = ''; |
290 | for ($i=0; isset($body_ary[$i]); $i++) { |
291 | if ($reply_id) { |
292 | if (ereg('^[ >]+', $body_ary[$i])) { |
01aab860 |
293 | $body_ary[$i] = '>' . $body_ary[$i]; |
734f4ee6 |
294 | } else { |
01aab860 |
295 | $body_ary[$i] = '> ' . $body_ary[$i]; |
296 | } |
297 | } |
a951522b |
298 | if (!$draft_id) { |
78a35fcd |
299 | sqWordWrap($body_ary[$i], $editor_size - 1); |
a951522b |
300 | } |
01aab860 |
301 | $body .= $body_ary[$i] . "\n"; |
f923b93d |
302 | unset($body_ary[$i]); |
48985d59 |
303 | } |
304 | if ($forward_id) { |
305 | $bodyTop = '-------- ' . _("Original Message") . " --------\n" . |
306 | _("Subject") . ': ' . $orig_header->subject . "\n" . |
307 | _("From") . ': ' . $orig_header->from . "\n" . |
78a35fcd |
308 | _("Date") . ': ' . |
309 | getLongDateString( $orig_header->date ). "\n" . |
48985d59 |
310 | _("To") . ': ' . $orig_header->to[0] . "\n"; |
78a35fcd |
311 | if (count($orig_header->to) > 1) { |
312 | for ($x=1; $x < count($orig_header->to); $x++) { |
313 | $bodyTop .= ' ' . $orig_header->to[$x] . "\n"; |
314 | } |
315 | } |
316 | $bodyTop .= "\n"; |
317 | $body = $bodyTop . $body; |
318 | } |
319 | elseif ($reply_id) { |
3b487216 |
320 | $orig_from = decodeHeader($orig_header->from, false); |
78a35fcd |
321 | $body = getReplyCitation($orig_from) . $body; |
322 | } |
9487c2ff |
323 | |
78a35fcd |
324 | return; |
48985d59 |
325 | } |
429f8906 |
326 | |
48985d59 |
327 | if (!$send_to) { |
78a35fcd |
328 | $send_to = sqimap_find_email($send_to); |
48985d59 |
329 | } |
29d08a52 |
330 | |
48985d59 |
331 | /* This formats a CC string if they hit "reply all" */ |
332 | if ($send_to_cc != '') { |
333 | $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc); |
0f8a1ce9 |
334 | $send_to_cc = str_replace(';', ',', $send_to_cc); |
48985d59 |
335 | $sendcc = explode(',', $send_to_cc); |
336 | $send_to_cc = ''; |
9487c2ff |
337 | |
48985d59 |
338 | for ($i = 0; $i < count($sendcc); $i++) { |
df15de21 |
339 | $sendcc[$i] = trim($sendcc[$i]); |
48985d59 |
340 | if ($sendcc[$i] == '') { |
341 | continue; |
342 | } |
9487c2ff |
343 | |
a53e5469 |
344 | $sendcc[$i] = sqimap_find_email($sendcc[$i]); |
48985d59 |
345 | $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']); |
346 | $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']); |
9487c2ff |
347 | |
df15de21 |
348 | if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) && |
349 | (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) && |
48985d59 |
350 | (trim($sendcc[$i]) != '')) { |
351 | $send_to_cc .= trim($sendcc[$i]) . ', '; |
df15de21 |
352 | } |
48985d59 |
353 | } |
354 | $send_to_cc = trim($send_to_cc); |
355 | if (substr($send_to_cc, -1) == ',') { |
df15de21 |
356 | $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1); |
48985d59 |
357 | } |
358 | } |
359 | } /* function newMail() */ |
360 | |
78509c54 |
361 | |
48985d59 |
362 | function getAttachments($message) { |
363 | global $mailbox, $attachments, $attachment_dir, $imapConnection, |
364 | $ent_num, $forward_id, $draft_id, $username; |
e707c74a |
365 | |
48985d59 |
366 | if (isset($draft_id)) { |
78a35fcd |
367 | $id = $draft_id; |
734f4ee6 |
368 | } else { |
78a35fcd |
369 | $id = $forward_id; |
48985d59 |
370 | } |
f972eb46 |
371 | |
48985d59 |
372 | if (!$message) { |
373 | sqimap_mailbox_select($imapConnection, $mailbox); |
374 | $message = sqimap_get_message($imapConnection, $id, $mailbox); |
375 | } |
9487c2ff |
376 | |
48985d59 |
377 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
378 | if (count($message->entities) == 0) { |
379 | if ($message->header->entity_id != $ent_num) { |
380 | $filename = decodeHeader($message->header->filename); |
5100704d |
381 | |
48985d59 |
382 | if ($filename == "") { |
383 | $filename = "untitled-".$message->header->entity_id; |
384 | } |
9487c2ff |
385 | |
48985d59 |
386 | $localfilename = GenerateRandomString(32, '', 7); |
387 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
388 | while (file_exists($full_localfilename)) { |
389 | $localfilename = GenerateRandomString(32, '', 7); |
390 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
391 | } |
0a17f9dd |
392 | |
48985d59 |
393 | $newAttachment = array(); |
394 | $newAttachment['localfilename'] = $localfilename; |
395 | $newAttachment['remotefilename'] = $filename; |
396 | $newAttachment['type'] = strtolower($message->header->type0 . |
78a35fcd |
397 | '/' . $message->header->type1); |
48985d59 |
398 | |
399 | /* Write Attachment to file */ |
400 | $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w'); |
401 | fputs($fp, decodeBody(mime_fetch_body($imapConnection, |
402 | $id, $message->header->entity_id), |
403 | $message->header->encoding)); |
404 | fclose ($fp); |
405 | |
406 | $attachments[] = $newAttachment; |
407 | } |
734f4ee6 |
408 | } else { |
48985d59 |
409 | for ($i = 0; $i < count($message->entities); $i++) { |
410 | getAttachments($message->entities[$i]); |
411 | } |
412 | } |
413 | return; |
414 | } |
415 | |
416 | function showInputForm () { |
417 | global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body, |
418 | $passed_body, $color, $use_signature, $signature, $prefix_sig, |
419 | $editor_size, $attachments, $subject, $newmail, |
420 | $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox, |
421 | $from_htmladdr_search, $location_of_buttons, $attachment_dir, |
422 | $username, $data_dir, $identity, $draft_id, $delete_draft, |
57257333 |
423 | $mailprio, $default_use_mdn, $mdn_user_support; |
48985d59 |
424 | |
3b487216 |
425 | $subject = decodeHeader($subject, false); |
426 | $reply_subj = decodeHeader($reply_subj, false); |
427 | $forward_subj = decodeHeader($forward_subj, false); |
48985d59 |
428 | |
429 | if ($use_javascript_addr_book) { |
430 | echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" . |
431 | 'function open_abook() { ' . "\n" . |
432 | ' var nwin = window.open("addrbook_popup.php","abookpopup",' . |
433 | '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" . |
434 | ' if((!nwin.opener) && (document.windows != null))' . "\n" . |
435 | ' nwin.opener = document.windows;' . "\n" . |
436 | "}\n" . |
437 | '// --></SCRIPT>' . "\n\n"; |
438 | } |
439 | |
440 | echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' . |
441 | 'ENCTYPE="multipart/form-data"'; |
442 | do_hook("compose_form"); |
57257333 |
443 | |
444 | |
48985d59 |
445 | echo ">\n"; |
446 | |
447 | if (isset($draft_id)) { |
448 | echo '<input type="hidden" name="delete_draft" value="' . $draft_id . "\">\n"; |
449 | } |
450 | if (isset($delete_draft)) { |
451 | echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n"; |
452 | } |
453 | |
454 | echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n"; |
455 | |
78a35fcd |
456 | if ($location_of_buttons == 'top') { |
457 | showComposeButtonRow(); |
458 | } |
48985d59 |
459 | |
715225af |
460 | $idents = getPref($data_dir, $username, 'identities', 0); |
461 | if ($idents > 1) { |
48985d59 |
462 | echo ' <TR>' . "\n" . |
463 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . |
464 | "\n" . |
465 | _("From:") . |
466 | ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
467 | '<select name=identity>' . "\n" . |
468 | '<option value=default>' . |
469 | htmlspecialchars(getPref($data_dir, $username, 'full_name')); |
470 | $em = getPref($data_dir, $username, 'email_address'); |
471 | if ($em != '') { |
248bfebb |
472 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
48985d59 |
473 | } |
474 | for ($i = 1; $i < $idents; $i ++) { |
248bfebb |
475 | echo '<option value="' . $i . '"'; |
48985d59 |
476 | if (isset($identity) && $identity == $i) { |
78a35fcd |
477 | echo ' SELECTED'; |
48985d59 |
478 | } |
479 | echo '>' . htmlspecialchars(getPref($data_dir, $username, |
480 | 'full_name' . $i)); |
248bfebb |
481 | $em = getPref($data_dir, $username, 'email_address' . $i); |
48985d59 |
482 | if ($em != '') { |
78a35fcd |
483 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
48985d59 |
484 | } |
485 | } |
486 | echo '</select>' . "\n" . |
487 | ' </TD>' . "\n" . |
488 | ' </TR>' . "\n"; |
489 | } |
490 | echo ' <TR>' . "\n" . |
491 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" . |
492 | _("To:") . |
493 | ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
494 | ' <INPUT TYPE=text NAME="send_to" VALUE="' . |
495 | htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" . |
496 | ' </TD>' . "\n" . |
497 | ' </TR>' . "\n" . |
498 | ' <TR>' . "\n" . |
499 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
500 | _("CC:") . |
501 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
502 | ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' . |
503 | htmlspecialchars($send_to_cc) . '"><BR>' . "\n" . |
504 | ' </TD>' . "\n" . |
505 | ' </TR>' . "\n" . |
506 | ' <TR>' . "\n" . |
507 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
508 | _("BCC:") . |
509 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
510 | ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' . |
511 | htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" . |
512 | '</TD></TR>' . "\n" . |
513 | ' <TR>' . "\n" . |
514 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
515 | _("Subject:") . |
516 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n"; |
517 | if ($reply_subj) { |
518 | $reply_subj = str_replace('"', "'", $reply_subj); |
519 | $reply_subj = trim($reply_subj); |
78a35fcd |
520 | if (substr(strtolower($reply_subj), 0, 3) != 're:') { |
48985d59 |
521 | $reply_subj = 'Re: ' . $reply_subj; |
78a35fcd |
522 | } |
48985d59 |
523 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
524 | htmlspecialchars($reply_subj) . '">'; |
78a35fcd |
525 | } |
526 | elseif ($forward_subj) { |
48985d59 |
527 | $forward_subj = trim($forward_subj); |
528 | if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') && |
529 | (substr(strtolower($forward_subj), 0, 5) != '[fwd:') && |
530 | (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) { |
531 | $forward_subj = '[Fwd: ' . $forward_subj . ']'; |
532 | } |
533 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
534 | htmlspecialchars($forward_subj) . '">'; |
734f4ee6 |
535 | } else { |
e707c74a |
536 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
48985d59 |
537 | htmlspecialchars($subject) . '">'; |
538 | } |
539 | echo '</td></tr>' . "\n\n"; |
540 | |
78a35fcd |
541 | if ($location_of_buttons == 'between') { |
542 | showComposeButtonRow(); |
543 | } |
48985d59 |
544 | |
545 | echo ' <TR>' . "\n" . |
546 | ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" . |
547 | ' <TEXTAREA NAME=body ROWS=20 COLS="' . |
548 | $editor_size . '" WRAP=HARD>' . htmlspecialchars($body); |
549 | if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) { |
3ba66ae8 |
550 | echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); |
48985d59 |
551 | } |
552 | echo '</TEXTAREA><BR>' . "\n" . |
553 | ' </TD>' . "\n" . |
554 | ' </TR>' . "\n"; |
555 | |
556 | if ($location_of_buttons == 'bottom') { |
557 | showComposeButtonRow(); |
558 | } else { |
559 | echo ' <TR><TD> </TD><TD ALIGN=LEFT><INPUT TYPE=SUBMIT ' . |
560 | 'NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n"; |
561 | } |
78a35fcd |
562 | |
48985d59 |
563 | /* This code is for attachments */ |
564 | echo ' <TR>' . "\n" . |
565 | ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" . |
566 | _("Attach:") . |
567 | ' </TD>' . "\n" . |
568 | ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" . |
569 | ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" . |
570 | ' <input type="submit" name="attach"' . |
571 | ' value="' . _("Add") .'">' . "\n" . |
572 | ' </TD>' . "\n" . |
573 | ' </TR>' . "\n"; |
574 | if (count($attachments)) { |
575 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
576 | echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" . |
577 | ' ' . |
578 | '</td><td align=left bgcolor="' . $color[0] . '">'; |
579 | foreach ($attachments as $key => $info) { |
3392dc86 |
580 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
48985d59 |
581 | echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" . |
582 | $info['remotefilename'] . ' - ' . $info['type'] . ' (' . |
583 | show_readable_size(filesize($attached_file)) . ")<br>\n"; |
584 | } |
585 | |
586 | echo '<input type="submit" name="do_delete" value="' . |
587 | _("Delete selected attachments") . "\">\n" . |
588 | '</td></tr>'; |
589 | } |
590 | /* End of attachment code */ |
591 | |
592 | echo '</TABLE>' . "\n"; |
593 | if ($reply_id) { |
594 | echo '<input type=hidden name=reply_id value=' . $reply_id . ">\n"; |
595 | } |
596 | echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) . |
597 | "\">\n" . |
598 | '</FORM>'; |
599 | do_hook("compose_bottom"); |
600 | echo '</BODY></HTML>' . "\n"; |
601 | } |
602 | |
603 | |
78a35fcd |
604 | function showComposeButtonRow() |
605 | { |
606 | global $use_javascript_addr_book, $save_as_draft, |
57257333 |
607 | $default_use_priority, $mailprio, $default_use_mdn; |
48985d59 |
608 | |
78a35fcd |
609 | echo " <TR><td>\n </td><td>\n"; |
610 | if ($use_javascript_addr_book) { |
611 | echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\""; |
612 | echo " <input type=button value=\\\""._("Addresses"). |
613 | "\\\" onclick='javascript:open_abook();'>\");"; |
614 | echo " // --></SCRIPT><NOSCRIPT>\n"; |
615 | echo " <input type=submit name=\"html_addr_search\" value=\"". |
616 | _("Addresses")."\">"; |
617 | echo " </NOSCRIPT>\n"; |
734f4ee6 |
618 | } else { |
78a35fcd |
619 | echo " <input type=submit name=\"html_addr_search\" value=\"". |
620 | _("Addresses")."\">"; |
621 | } |
622 | echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n"; |
48985d59 |
623 | |
78a35fcd |
624 | if ($save_as_draft) { |
625 | echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n"; |
626 | } |
627 | if ($default_use_priority) { |
020abcf3 |
628 | if(!isset($mailprio)) { |
78a35fcd |
629 | $mailprio = "3"; |
630 | } |
631 | echo "\n\t". _("Priority") .':<select name="mailprio">'. |
632 | "\n\t\t<option value=1".($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'. |
633 | "\n\t\t<option value=3".($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'. |
634 | "\n\t\t<option value=5".($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'. |
635 | "\n\t</select>"; |
e707c74a |
636 | } |
0a17f9dd |
637 | |
57257333 |
638 | $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn); |
639 | if ($default_use_mdn) { |
640 | if ($mdn_user_support) { |
641 | echo _("Confirm reading:"). |
642 | "<input type=\"checkbox\" name=\"request_mdn\" value=1>"; |
643 | } |
644 | } |
645 | |
78a35fcd |
646 | do_hook('compose_button_row'); |
441f2d33 |
647 | |
78a35fcd |
648 | echo " </TD>\n"; |
649 | echo " </TR>\n\n"; |
650 | } |
b278172f |
651 | |
78a35fcd |
652 | function checkInput ($show) |
653 | { |
654 | /* |
655 | * I implemented the $show variable because the error messages |
656 | * were getting sent before the page header. So, I check once |
657 | * using $show=false, and then when i'm ready to display the error |
658 | * message, show=true |
659 | */ |
660 | global $body, $send_to, $subject, $color; |
661 | |
662 | if ($send_to == "") { |
663 | if ($show) { |
0ad7dbda |
664 | plain_error_message(_("You have not filled in the \"To:\" field."), $color); |
78a35fcd |
665 | } |
666 | return false; |
667 | } |
668 | return true; |
669 | } /* function checkInput() */ |
df15de21 |
670 | |
3806fa52 |
671 | |
00793a25 |
672 | /* True if FAILURE */ |
4c9d2242 |
673 | function saveAttachedFiles() { |
674 | global $HTTP_POST_FILES, $attachment_dir, $attachments, $username; |
675 | |
676 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
677 | $localfilename = GenerateRandomString(32, '', 7); |
678 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
679 | while (file_exists($full_localfilename)) { |
680 | $localfilename = GenerateRandomString(32, '', 7); |
681 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
682 | } |
683 | |
684 | if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
685 | if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
056ddad7 |
686 | return true; |
4c9d2242 |
687 | } |
688 | } |
9487c2ff |
689 | |
4c9d2242 |
690 | $newAttachment['localfilename'] = $localfilename; |
691 | $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name']; |
692 | $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']); |
8ef72f33 |
693 | |
4c9d2242 |
694 | if ($newAttachment['type'] == "") { |
8ef72f33 |
695 | $newAttachment['type'] = 'application/octet-stream'; |
056ddad7 |
696 | } |
9487c2ff |
697 | |
4c9d2242 |
698 | $attachments[] = $newAttachment; |
699 | } |
700 | |
4c9d2242 |
701 | |
57257333 |
702 | |
703 | |
4c9d2242 |
704 | function ClearAttachments() |
705 | { |
706 | global $username, $attachments, $attachment_dir; |
707 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
708 | |
709 | foreach ($attachments as $info) { |
710 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
711 | if (file_exists($attached_file)) { |
712 | unlink($attached_file); |
713 | } |
714 | } |
715 | |
716 | $attachments = array(); |
717 | } |
718 | |
719 | function getReplyCitation($orig_from) |
720 | { |
721 | global $reply_citation_style, $reply_citation_start, $reply_citation_end; |
722 | |
723 | /* First, return an empty string when no citation style selected. */ |
724 | if (($reply_citation_style == '') || ($reply_citation_style == 'none')) { |
725 | return ''; |
726 | } |
727 | |
728 | /* Decode the users name. */ |
729 | $parpos = strpos($orig_from, '('); |
730 | if ($parpos === false) { |
731 | $orig_from = trim(substr($orig_from, 0, strpos($orig_from, '<'))); |
732 | $orig_from = str_replace('"', '', $orig_from); |
733 | $orig_from = str_replace("'", '', $orig_from); |
734f4ee6 |
734 | } else { |
4c9d2242 |
735 | $end_parpos = strrpos($orig_from, ')'); |
736 | $end_parpos -= ($end_parpos === false ? $end_parpos : $parpos + 1); |
737 | $orig_from = trim(substr($orig_from, $parpos + 1, $end_parpos)); |
738 | } |
739 | |
740 | /* Make sure our final value isn't an empty string. */ |
741 | if ($orig_from == '') { |
742 | return ''; |
743 | } |
744 | |
745 | /* Otherwise, try to select the desired citation style. */ |
746 | switch ($reply_citation_style) { |
747 | case 'author_said': |
748 | $start = ''; |
749 | $end = ' ' . _("said") . ':'; |
750 | break; |
751 | case 'quote_who': |
752 | $start = '<' . _("quote") . ' ' . _("who") . '="'; |
753 | $end = '">'; |
754 | break; |
755 | case 'user-defined': |
756 | $start = $reply_citation_start; |
757 | $end = $reply_citation_end; |
758 | break; |
759 | default: |
760 | return ''; |
761 | } |
762 | |
763 | /* Build and return the citation string. */ |
764 | return ($start . $orig_from . $end . "\n"); |
765 | } |
766 | |
0a17f9dd |
767 | ?> |