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