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