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 | } |
9f599fe3 |
485 | echo '</option>'; |
48985d59 |
486 | } |
487 | echo '</select>' . "\n" . |
488 | ' </TD>' . "\n" . |
489 | ' </TR>' . "\n"; |
490 | } |
491 | echo ' <TR>' . "\n" . |
492 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" . |
493 | _("To:") . |
494 | ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
495 | ' <INPUT TYPE=text NAME="send_to" VALUE="' . |
496 | htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" . |
497 | ' </TD>' . "\n" . |
498 | ' </TR>' . "\n" . |
499 | ' <TR>' . "\n" . |
500 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
501 | _("CC:") . |
502 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
503 | ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' . |
504 | htmlspecialchars($send_to_cc) . '"><BR>' . "\n" . |
505 | ' </TD>' . "\n" . |
506 | ' </TR>' . "\n" . |
507 | ' <TR>' . "\n" . |
508 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
509 | _("BCC:") . |
510 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
511 | ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' . |
512 | htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" . |
513 | '</TD></TR>' . "\n" . |
514 | ' <TR>' . "\n" . |
515 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
516 | _("Subject:") . |
517 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n"; |
518 | if ($reply_subj) { |
519 | $reply_subj = str_replace('"', "'", $reply_subj); |
520 | $reply_subj = trim($reply_subj); |
78a35fcd |
521 | if (substr(strtolower($reply_subj), 0, 3) != 're:') { |
48985d59 |
522 | $reply_subj = 'Re: ' . $reply_subj; |
78a35fcd |
523 | } |
48985d59 |
524 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
525 | htmlspecialchars($reply_subj) . '">'; |
78a35fcd |
526 | } |
527 | elseif ($forward_subj) { |
48985d59 |
528 | $forward_subj = trim($forward_subj); |
529 | if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') && |
530 | (substr(strtolower($forward_subj), 0, 5) != '[fwd:') && |
531 | (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) { |
532 | $forward_subj = '[Fwd: ' . $forward_subj . ']'; |
533 | } |
534 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
535 | htmlspecialchars($forward_subj) . '">'; |
734f4ee6 |
536 | } else { |
e707c74a |
537 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
48985d59 |
538 | htmlspecialchars($subject) . '">'; |
539 | } |
540 | echo '</td></tr>' . "\n\n"; |
541 | |
78a35fcd |
542 | if ($location_of_buttons == 'between') { |
543 | showComposeButtonRow(); |
544 | } |
48985d59 |
545 | |
546 | echo ' <TR>' . "\n" . |
547 | ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" . |
548 | ' <TEXTAREA NAME=body ROWS=20 COLS="' . |
549 | $editor_size . '" WRAP=HARD>' . htmlspecialchars($body); |
550 | if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) { |
3ba66ae8 |
551 | echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); |
48985d59 |
552 | } |
553 | echo '</TEXTAREA><BR>' . "\n" . |
554 | ' </TD>' . "\n" . |
555 | ' </TR>' . "\n"; |
556 | |
557 | if ($location_of_buttons == 'bottom') { |
558 | showComposeButtonRow(); |
559 | } else { |
9f599fe3 |
560 | echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>'; |
561 | |
562 | $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn); |
563 | if ($default_use_mdn) { |
564 | if ($mdn_user_support) { |
565 | echo _("Confirm reading:"). |
566 | "<input type=\"checkbox\" name=\"request_mdn\" value=1>"; |
567 | } |
568 | } |
569 | echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n"; |
48985d59 |
570 | } |
46bb8da8 |
571 | |
48985d59 |
572 | /* This code is for attachments */ |
573 | echo ' <TR>' . "\n" . |
574 | ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" . |
575 | _("Attach:") . |
576 | ' </TD>' . "\n" . |
577 | ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" . |
578 | ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" . |
579 | ' <input type="submit" name="attach"' . |
580 | ' value="' . _("Add") .'">' . "\n" . |
581 | ' </TD>' . "\n" . |
582 | ' </TR>' . "\n"; |
9f599fe3 |
583 | |
48985d59 |
584 | if (count($attachments)) { |
585 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
586 | echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" . |
587 | ' ' . |
588 | '</td><td align=left bgcolor="' . $color[0] . '">'; |
589 | foreach ($attachments as $key => $info) { |
3392dc86 |
590 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
48985d59 |
591 | echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" . |
592 | $info['remotefilename'] . ' - ' . $info['type'] . ' (' . |
593 | show_readable_size(filesize($attached_file)) . ")<br>\n"; |
594 | } |
595 | |
596 | echo '<input type="submit" name="do_delete" value="' . |
597 | _("Delete selected attachments") . "\">\n" . |
598 | '</td></tr>'; |
599 | } |
600 | /* End of attachment code */ |
601 | |
602 | echo '</TABLE>' . "\n"; |
603 | if ($reply_id) { |
604 | echo '<input type=hidden name=reply_id value=' . $reply_id . ">\n"; |
605 | } |
606 | echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) . |
607 | "\">\n" . |
608 | '</FORM>'; |
9f599fe3 |
609 | do_hook('compose_bottom'); |
48985d59 |
610 | echo '</BODY></HTML>' . "\n"; |
611 | } |
612 | |
613 | |
78a35fcd |
614 | function showComposeButtonRow() |
615 | { |
616 | global $use_javascript_addr_book, $save_as_draft, |
46bb8da8 |
617 | $default_use_priority, $mailprio, $default_use_mdn, |
618 | $data_dir, $username; |
48985d59 |
619 | |
78a35fcd |
620 | echo " <TR><td>\n </td><td>\n"; |
621 | if ($use_javascript_addr_book) { |
46bb8da8 |
622 | echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"". |
623 | " <input type=button value=\\\""._("Addresses"). |
624 | "\\\" onclick='javascript:open_abook();'>\");". |
625 | " // --></SCRIPT><NOSCRIPT>\n". |
626 | " <input type=submit name=\"html_addr_search\" value=\"". |
627 | _("Addresses")."\">". |
628 | " </NOSCRIPT>\n"; |
734f4ee6 |
629 | } else { |
78a35fcd |
630 | echo " <input type=submit name=\"html_addr_search\" value=\"". |
631 | _("Addresses")."\">"; |
632 | } |
633 | echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n"; |
48985d59 |
634 | |
78a35fcd |
635 | if ($save_as_draft) { |
636 | echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n"; |
637 | } |
638 | if ($default_use_priority) { |
020abcf3 |
639 | if(!isset($mailprio)) { |
78a35fcd |
640 | $mailprio = "3"; |
641 | } |
46bb8da8 |
642 | echo _("Priority") .':<select name="mailprio">'. |
643 | "<option value=1".($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'. |
644 | "<option value=3".($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'. |
645 | "<option value=5".($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'. |
646 | "</select>"; |
e707c74a |
647 | } |
0a17f9dd |
648 | |
78a35fcd |
649 | do_hook('compose_button_row'); |
441f2d33 |
650 | |
46bb8da8 |
651 | echo " </TD></TR>\n\n"; |
78a35fcd |
652 | } |
b278172f |
653 | |
78a35fcd |
654 | function checkInput ($show) |
655 | { |
656 | /* |
657 | * I implemented the $show variable because the error messages |
658 | * were getting sent before the page header. So, I check once |
659 | * using $show=false, and then when i'm ready to display the error |
660 | * message, show=true |
661 | */ |
662 | global $body, $send_to, $subject, $color; |
663 | |
664 | if ($send_to == "") { |
665 | if ($show) { |
0ad7dbda |
666 | plain_error_message(_("You have not filled in the \"To:\" field."), $color); |
78a35fcd |
667 | } |
668 | return false; |
669 | } |
670 | return true; |
671 | } /* function checkInput() */ |
df15de21 |
672 | |
3806fa52 |
673 | |
00793a25 |
674 | /* True if FAILURE */ |
4c9d2242 |
675 | function saveAttachedFiles() { |
676 | global $HTTP_POST_FILES, $attachment_dir, $attachments, $username; |
677 | |
678 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
679 | $localfilename = GenerateRandomString(32, '', 7); |
680 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
681 | while (file_exists($full_localfilename)) { |
682 | $localfilename = GenerateRandomString(32, '', 7); |
683 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
684 | } |
685 | |
686 | if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
687 | if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
056ddad7 |
688 | return true; |
4c9d2242 |
689 | } |
690 | } |
9487c2ff |
691 | |
4c9d2242 |
692 | $newAttachment['localfilename'] = $localfilename; |
693 | $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name']; |
694 | $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']); |
8ef72f33 |
695 | |
4c9d2242 |
696 | if ($newAttachment['type'] == "") { |
8ef72f33 |
697 | $newAttachment['type'] = 'application/octet-stream'; |
056ddad7 |
698 | } |
9487c2ff |
699 | |
4c9d2242 |
700 | $attachments[] = $newAttachment; |
701 | } |
702 | |
4c9d2242 |
703 | |
57257333 |
704 | |
705 | |
4c9d2242 |
706 | function ClearAttachments() |
707 | { |
708 | global $username, $attachments, $attachment_dir; |
709 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
710 | |
711 | foreach ($attachments as $info) { |
712 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
713 | if (file_exists($attached_file)) { |
714 | unlink($attached_file); |
715 | } |
716 | } |
717 | |
718 | $attachments = array(); |
719 | } |
720 | |
721 | function getReplyCitation($orig_from) |
722 | { |
723 | global $reply_citation_style, $reply_citation_start, $reply_citation_end; |
724 | |
725 | /* First, return an empty string when no citation style selected. */ |
726 | if (($reply_citation_style == '') || ($reply_citation_style == 'none')) { |
727 | return ''; |
728 | } |
729 | |
730 | /* Decode the users name. */ |
731 | $parpos = strpos($orig_from, '('); |
732 | if ($parpos === false) { |
733 | $orig_from = trim(substr($orig_from, 0, strpos($orig_from, '<'))); |
734 | $orig_from = str_replace('"', '', $orig_from); |
735 | $orig_from = str_replace("'", '', $orig_from); |
734f4ee6 |
736 | } else { |
4c9d2242 |
737 | $end_parpos = strrpos($orig_from, ')'); |
738 | $end_parpos -= ($end_parpos === false ? $end_parpos : $parpos + 1); |
739 | $orig_from = trim(substr($orig_from, $parpos + 1, $end_parpos)); |
740 | } |
741 | |
742 | /* Make sure our final value isn't an empty string. */ |
743 | if ($orig_from == '') { |
744 | return ''; |
745 | } |
746 | |
747 | /* Otherwise, try to select the desired citation style. */ |
748 | switch ($reply_citation_style) { |
749 | case 'author_said': |
750 | $start = ''; |
751 | $end = ' ' . _("said") . ':'; |
752 | break; |
753 | case 'quote_who': |
754 | $start = '<' . _("quote") . ' ' . _("who") . '="'; |
755 | $end = '">'; |
756 | break; |
757 | case 'user-defined': |
758 | $start = $reply_citation_start; |
759 | $end = $reply_citation_end; |
760 | break; |
761 | default: |
762 | return ''; |
763 | } |
764 | |
765 | /* Build and return the citation string. */ |
766 | return ($start . $orig_from . $end . "\n"); |
767 | } |
768 | |
0a17f9dd |
769 | ?> |