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