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