Small option changes.
[squirrelmail.git] / src / compose.php
1 <?php
2 /**
3 * compose.php
4 *
5 * Copyright (c) 1999-2000 The SquirrelMail development team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This code sends a mail.
9 *
10 * There are 4 modes of operation:
11 * - Start new mail
12 * - Add an attachment
13 * - Send mail
14 * - Save As Draft
15 *
16 * $Id$
17 **/
18
19 require_once('../src/validate.php');
20 require_once('../functions/imap.php');
21 require_once('../functions/date.php');
22 require_once('../functions/mime.php');
23 require_once('../functions/smtp.php');
24 require_once('../functions/display_messages.php');
25 require_once('../functions/plugin.php');
26
27 if (!isset($attachments))
28 {
29 $attachments = array();
30 session_register('attachments');
31 }
32
33
34 // This function is used when not sending or adding attachments
35 function newMail () {
36 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
37 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size,
38 $draft_id, $use_signature;
39
40 $send_to = decodeHeader($send_to);
41 $send_to_cc = decodeHeader($send_to_cc);
42 $send_to_bcc = decodeHeader($send_to_bcc);
43
44 if ($forward_id)
45 $id = $forward_id;
46 elseif ($reply_id)
47 $id = $reply_id;
48
49 if ($draft_id){
50 $id = $draft_id;
51 $use_signature = FALSE;
52 }
53
54 if (isset($id)) {
55 sqimap_mailbox_select($imapConnection, $mailbox);
56 $message = sqimap_get_message($imapConnection, $id, $mailbox);
57 $orig_header = $message->header;
58 if ($ent_num)
59 $message = getEntity($message, $ent_num);
60
61 if ($message->header->type0 == 'text' || $message->header->type1 == 'message') {
62 if ($ent_num)
63 $body = decodeBody(mime_fetch_body($imapConnection, $id, $ent_num), $message->header->encoding);
64 else
65 $body = decodeBody(mime_fetch_body($imapConnection, $id, 1), $message->header->encoding);
66 } else {
67 $body = "";
68 }
69
70 if ($message->header->type1 == "html")
71 $body = strip_tags($body);
72
73 sqUnWordWrap($body);
74 $body_ary = explode("\n", $body);
75 $i = count($body_ary) - 1;
76 while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
77 unset($body_ary[$i]);
78 $i --;
79 }
80 $body = "";
81 for ($i=0; isset($body_ary[$i]); $i++) {
82 if ($reply_id)
83 {
84 if (ereg('^[ >]+', $body_ary[$i]))
85 {
86 $body_ary[$i] = '>' . $body_ary[$i];
87 }
88 else
89 {
90 $body_ary[$i] = '> ' . $body_ary[$i];
91 }
92 }
93 if (!$draft_id) {
94 sqWordWrap($body_ary[$i], $editor_size - 1);
95 }
96 $body .= $body_ary[$i] . "\n";
97 unset($body_ary[$i]);
98 }
99 if ($forward_id)
100 {
101 $bodyTop = "-------- " . _("Original Message") . " --------\n";
102 $bodyTop .= _("Subject") . ": " . $orig_header->subject . "\n";
103 $bodyTop .= _("From") . ": " . $orig_header->from . "\n";
104 $bodyTop .= _("To") . ": " . $orig_header->to[0] . "\n";
105 if (count($orig_header->to) > 1) {
106 for ($x=1; $x < count($orig_header->to); $x++) {
107 $bodyTop .= " " . $orig_header->to[$x] . "\n";
108 }
109 }
110 $bodyTop .= "\n";
111 $body = $bodyTop . $body;
112 } else if ($reply_id) {
113 $orig_from = decodeHeader($orig_header->from);
114 $orig_from = trim(substr($orig_from,0,strpos($orig_from,'<')));
115 $orig_from = str_replace('"','',$orig_from);
116 $orig_from = str_replace("'",'',$orig_from);
117 $body = getReplyCitation($orig_from) . $body;
118 }
119
120 return;
121 }
122
123 if (!$send_to) {
124 $send_to = sqimap_find_email($send_to);
125 }
126
127 /** This formats a CC string if they hit "reply all" **/
128 if ($send_to_cc != "") {
129 $send_to_cc = ereg_replace( '"[^"]*"', "", $send_to_cc);
130 $send_to_cc = ereg_replace(";", ",", $send_to_cc);
131 $sendcc = explode(",", $send_to_cc);
132 $send_to_cc = "";
133
134 for ($i = 0; $i < count($sendcc); $i++) {
135 $sendcc[$i] = trim($sendcc[$i]);
136 if ($sendcc[$i] == "")
137 continue;
138
139 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
140 $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]);
141 $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]);
142
143 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
144 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
145 (trim($sendcc[$i]) != "")) {
146 $send_to_cc .= trim($sendcc[$i]) . ", ";
147 }
148 }
149 $send_to_cc = trim($send_to_cc);
150 if (substr($send_to_cc, -1) == ",") {
151 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
152 }
153 }
154 } // function newMail()
155
156 function getAttachments($message) {
157 global $mailbox, $attachments, $attachment_dir, $imapConnection,
158 $ent_num, $forward_id, $draft_id;
159
160 if (isset($draft_id))
161 $id = $draft_id;
162 else
163 $id = $forward_id;
164
165 if (!$message) {
166 sqimap_mailbox_select($imapConnection, $mailbox);
167 $message = sqimap_get_message($imapConnection, $id,
168 $mailbox);
169 }
170
171 if (count($message->entities) == 0) {
172 if ($message->header->entity_id != $ent_num) {
173 $filename = decodeHeader($message->header->filename);
174
175 if ($filename == "")
176 $filename = "untitled-".$message->header->entity_id;
177
178 $localfilename = GenerateRandomString(32, '', 7);
179 while (file_exists($attachment_dir . $localfilename))
180 $localfilename = GenerateRandomString(32, '', 7);
181
182 $newAttachment = array();
183 $newAttachment['localfilename'] = $localfilename;
184 $newAttachment['remotefilename'] = $filename;
185 $newAttachment['type'] = strtolower($message->header->type0 .
186 '/' . $message->header->type1);
187
188 // Write Attachment to file
189 $fp = fopen ($attachment_dir.$localfilename, 'w');
190 fputs ($fp, decodeBody(mime_fetch_body($imapConnection,
191 $id, $message->header->entity_id),
192 $message->header->encoding));
193 fclose ($fp);
194
195 $attachments[] = $newAttachment;
196 }
197 } else {
198 for ($i = 0; $i < count($message->entities); $i++) {
199 getAttachments($message->entities[$i]);
200 }
201 }
202 return;
203 }
204
205 function showInputForm () {
206 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
207 $passed_body, $color, $use_signature, $signature, $prefix_sig,
208 $editor_size, $attachments, $subject, $newmail,
209 $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
210 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
211 $username, $data_dir, $identity, $draft_id, $delete_draft,
212 $mailprio;
213
214 $subject = decodeHeader($subject);
215 $reply_subj = decodeHeader($reply_subj);
216 $forward_subj = decodeHeader($forward_subj);
217
218 if ($use_javascript_addr_book) {
219 echo "\n<SCRIPT LANGUAGE=JavaScript><!--\n";
220 echo "function open_abook() { \n";
221 echo " var nwin = window.open(\"addrbook_popup.php\",\"abookpopup\",";
222 echo "\"width=670,height=300,resizable=yes,scrollbars=yes\");\n";
223 echo " if((!nwin.opener) && (document.windows != null))\n";
224 echo " nwin.opener = document.windows;\n";
225 echo "}\n";
226 echo "// --></SCRIPT>\n\n";
227 }
228
229 echo "\n<FORM name=compose action=\"compose.php\" METHOD=POST ENCTYPE=\"multipart/form-data\"";
230 do_hook("compose_form");
231 echo ">\n";
232
233 if (isset($draft_id)) {
234 echo "<input type=\"hidden\" name=\"delete_draft\" value=\"$draft_id\">\n";
235 }
236 if (isset($delete_draft)) {
237 echo "<input type=\"hidden\" name=\"delete_draft\" value=\"$delete_draft\">\n";
238 }
239
240 echo "<TABLE WIDTH=\"100%\" ALIGN=center CELLSPACING=0 BORDER=0>\n";
241
242 if ($location_of_buttons == 'top') showComposeButtonRow();
243
244 $idents = getPref($data_dir, $username, 'identities');
245 if ($idents != '' && $idents > 1) {
246 echo " <TR>\n";
247 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=\"10%\" ALIGN=RIGHT>\n";
248 echo _("From:");
249 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=\"90%\">\n";
250 echo "<select name=identity>\n";
251 echo "<option value=default>" .
252 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
253 $em = getPref($data_dir, $username, 'email_address');
254 if ($em != '')
255 echo htmlspecialchars(' <' . $em . '>') . "\n";
256 for ($i = 1; $i < $idents; $i ++) {
257 echo '<option value="' . $i . '"';
258 if (isset($identity) && $identity == $i)
259 echo ' SELECTED';
260 echo '>';
261 echo htmlspecialchars(getPref($data_dir, $username, 'full_name' .
262 $i));
263 $em = getPref($data_dir, $username, 'email_address' . $i);
264 if ($em != '')
265 echo htmlspecialchars(' <' . $em . '>') . "\n";
266 }
267 echo "</select>\n";
268 echo " </TD>\n";
269 echo " </TR>\n";
270 }
271 echo " <TR>\n";
272 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=\"10%\" ALIGN=RIGHT>\n";
273 echo _("To:");
274 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=\"90%\">\n";
275 printf(" <INPUT TYPE=text NAME=\"send_to\" VALUE=\"%s\" SIZE=60><BR>\n",
276 htmlspecialchars($send_to));
277 echo " </TD>\n";
278 echo " </TR>\n";
279 echo " <TR>\n";
280 echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
281 echo _("CC:");
282 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
283 printf(" <INPUT TYPE=text NAME=\"send_to_cc\" SIZE=60 VALUE=\"%s\"><BR>\n",
284 htmlspecialchars($send_to_cc));
285 echo " </TD>\n";
286 echo " </TR>\n";
287 echo " <TR>\n";
288 echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
289 echo _("BCC:");
290 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
291 printf(" <INPUT TYPE=text NAME=\"send_to_bcc\" VALUE=\"%s\" SIZE=60><BR>\n",
292 htmlspecialchars($send_to_bcc));
293 echo "</TD></TR>\n";
294
295 echo " <TR>\n";
296 echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
297 echo _("Subject:");
298 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
299 if ($reply_subj) {
300 $reply_subj = str_replace("\"", "'", $reply_subj);
301 $reply_subj = trim($reply_subj);
302 if (substr(strtolower($reply_subj), 0, 3) != "re:")
303 $reply_subj = "Re: $reply_subj";
304 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
305 htmlspecialchars($reply_subj));
306 } else if ($forward_subj) {
307 $forward_subj = trim($forward_subj);
308 if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
309 (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
310 (substr(strtolower($forward_subj), 0, 6) != '[ fwd:'))
311 $forward_subj = "[Fwd: $forward_subj]";
312 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
313 htmlspecialchars($forward_subj));
314 } else {
315 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
316 htmlspecialchars($subject));
317 }
318 echo "</td></tr>\n\n";
319
320 if ($location_of_buttons == 'between') showComposeButtonRow();
321
322 echo " <TR>\n";
323 echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=2>\n";
324 echo " &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>";
325 echo htmlspecialchars($body);
326 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
327 if ( $prefix_sig == true )
328 echo "\n\n-- \n" . htmlspecialchars($signature);
329 else
330 echo "\n\n" . htmlspecialchars($signature);
331 }
332 echo "</TEXTAREA><BR>\n";
333 echo " </TD>\n";
334 echo " </TR>\n";
335
336 if ($location_of_buttons == 'bottom')
337 showComposeButtonRow();
338 else {
339 echo " <TR><TD>&nbsp;</TD><TD ALIGN=LEFT><INPUT TYPE=SUBMIT NAME=send VALUE=\""._("Send")."\"></TD></TR>\n";
340 }
341
342 // This code is for attachments
343 echo " <tr>\n";
344 echo " <TD BGCOLOR=\"$color[0]\" VALIGN=MIDDLE ALIGN=RIGHT>\n";
345 echo _("Attach:");
346 echo " </td><td ALIGN=left BGCOLOR=\"$color[0]\">\n";
347 echo " <INPUT NAME=\"attachfile\" SIZE=48 TYPE=\"file\">\n";
348 echo " &nbsp;&nbsp;<input type=\"submit\" name=\"attach\"";
349 echo " value=\"" . _("Add") ."\">\n";
350 echo " </td>\n";
351 echo " </tr>\n";
352 if (count($attachments))
353 {
354 echo "<tr><td bgcolor=\"$color[0]\" align=right>\n";
355 echo "&nbsp;";
356 echo "</td><td align=left bgcolor=\"$color[0]\">";
357 foreach ($attachments as $key => $info) {
358 echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$key\">\n";
359 echo $info['remotefilename'] . " - " . $info['type'] . " (";
360 echo show_readable_size(filesize($attachment_dir .
361 $info['localfilename'])) . ")<br>\n";
362 }
363
364 echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
365 echo "</td></tr>";
366 }
367 // End of attachment code
368
369 echo "</TABLE>\n";
370 if ($reply_id) {
371 echo "<input type=hidden name=reply_id value=$reply_id>\n";
372 }
373 printf("<INPUT TYPE=hidden NAME=mailbox VALUE=\"%s\">\n", htmlspecialchars($mailbox));
374 echo "</FORM>";
375 do_hook("compose_bottom");
376 echo "</BODY></HTML>\n";
377 }
378
379 function showComposeButtonRow() {
380 global $use_javascript_addr_book, $save_as_draft,
381 $default_use_priority, $mailprio;
382
383 echo " <TR><td>\n </td><td>\n";
384 if ($use_javascript_addr_book) {
385 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"";
386 echo " <input type=button value=\\\""._("Addresses")."\\\" onclick='javascript:open_abook();'>\");";
387 echo " // --></SCRIPT><NOSCRIPT>\n";
388 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
389 echo " </NOSCRIPT>\n";
390 } else {
391 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
392 }
393 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
394
395 if ($save_as_draft) {
396 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
397 }
398 if ($default_use_priority) {
399 if(!isset($mailprio)) {
400 $mailprio = "3";
401 }
402 echo "\n\t". _("Priority") .":<select name=\"mailprio\">".
403 "\n\t\t<option value=1".($mailprio=="1"?" selected":"").">". _("High") ."</option>".
404 "\n\t\t<option value=3".($mailprio=="3"?" selected":"").">". _("Normal") ."</option>".
405 "\n\t\t<option value=5".($mailprio=="5"?" selected":"").">". _("Low")."</option>".
406 "\n\t</select>";
407 }
408
409 do_hook("compose_button_row");
410
411 echo " </TD>\n";
412 echo " </TR>\n\n";
413 }
414
415 function checkInput ($show) {
416 /** I implemented the $show variable because the error messages
417 were getting sent before the page header. So, I check once
418 using $show=false, and then when i'm ready to display the
419 error message, show=true **/
420 global $body, $send_to, $subject, $color;
421
422 if ($send_to == "") {
423 if ($show)
424 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
425 return false;
426 }
427 return true;
428 } // function checkInput()
429
430
431 // True if FAILURE
432 function saveAttachedFiles() {
433 global $HTTP_POST_FILES, $attachment_dir, $attachments;
434
435 $localfilename = GenerateRandomString(32, '', 7);
436 while (file_exists($attachment_dir . $localfilename))
437 $localfilename = GenerateRandomString(32, '', 7);
438
439 if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {
440 if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {
441 return true;
442 }
443 }
444
445 $newAttachment['localfilename'] = $localfilename;
446 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
447 $newAttachment['type'] =
448 strtolower($HTTP_POST_FILES['attachfile']['type']);
449
450 if ($newAttachment['type'] == "")
451 $newAttachment['type'] = 'application/octet-stream';
452
453 $attachments[] = $newAttachment;
454 }
455
456 if (!isset($mailbox) || $mailbox == "" || ($mailbox == "None"))
457 $mailbox = "INBOX";
458
459 if (isset($draft)) {
460 require_once ('../src/draft_actions.php');
461 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) {
462 showInputForm();
463 exit();
464 } else {
465 $draft_message = _("Draft Email Saved");
466 /* If this is a resumed draft, then delete the original */
467 if(isset($delete_draft)) {
468 Header("Location: delete_message.php?mailbox=$draft_folder&message=$delete_draft&sort=$sort&startMessage=1");
469 exit();
470 } else {
471 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort&startMessage=1&note=$draft_message");
472 exit();
473 }
474 }
475 }
476
477 if (isset($send)) {
478 if (isset($HTTP_POST_FILES['attachfile']) &&
479 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
480 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none')
481 $AttachFailure = saveAttachedFiles();
482 if (checkInput(false) && !isset($AttachFailure)) {
483 $urlMailbox = urlencode (trim($mailbox));
484 if (! isset($reply_id))
485 $reply_id = 0;
486 // Set $default_charset to correspond with the user's selection
487 // of language interface.
488 set_my_charset();
489
490 // This is to change all newlines to \n
491 // We'll change them to \r\n later (in the sendMessage function)
492 $body = str_replace("\r\n", "\n", $body);
493 $body = str_replace("\r", "\n", $body);
494
495 // Rewrap $body so that no line is bigger than $editor_size
496 // This should only really kick in the sqWordWrap function
497 // if the browser doesn't support "HARD" as the wrap type
498 // Or, in Opera's case, something goes wrong.
499 $body = explode("\n", $body);
500 $newBody = '';
501 foreach ($body as $line) {
502 if( $line <> '-- ' )
503 $line = rtrim($line);
504 if (strlen($line) <= $editor_size + 1)
505 $newBody .= $line . "\n";
506 else {
507 sqWordWrap($line, $editor_size) . "\n";
508 $newBody .= $line;
509 }
510 }
511 $body = $newBody;
512
513 do_hook("compose_send");
514
515 if (! isset($mailprio))
516 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
517 $subject, $body, $reply_id);
518 else
519 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
520 $subject, $body, $reply_id, $mailprio);
521 if (! $Result) {
522 showInputForm();
523 exit();
524 }
525 if ( isset($delete_draft)) {
526 Header("Location: delete_message.php?mailbox=$draft_folder&message=$delete_draft&sort=$sort&startMessage=1");
527 exit();
528 }
529
530 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
531 } else {
532 //$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
533 displayPageHeader($color, $mailbox);
534
535 if (isset($AttachFailure))
536 plain_error_message(_("Could not move/copy file. File not attached"), $color);
537
538 checkInput(true);
539
540 showInputForm();
541 //sqimap_logout($imapConnection);
542 }
543 } else if (isset($html_addr_search_done)) {
544 displayPageHeader($color, $mailbox);
545
546 if (isset($send_to_search) && is_array($send_to_search)) {
547 foreach ($send_to_search as $k => $v) {
548 if (substr($k, 0, 1) == 'T') {
549 if ($send_to)
550 $send_to .= ', ';
551 $send_to .= $v;
552 }
553 elseif (substr($k, 0, 1) == 'C') {
554 if ($send_to_cc)
555 $send_to_cc .= ', ';
556 $send_to_cc .= $v;
557 }
558 elseif (substr($k, 0, 1) == 'B') {
559 if ($send_to_bcc)
560 $send_to_bcc .= ', ';
561 $send_to_bcc .= $v;
562 }
563 }
564 }
565
566 showInputForm();
567 } else if (isset($html_addr_search)) {
568 if (isset($HTTP_POST_FILES['attachfile']) &&
569 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
570 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none')
571 {
572 if (saveAttachedFiles())
573 plain_error_message(_("Could not move/copy file. File not attached"), $color);
574 }
575 // I am using an include so as to elminiate an extra unnecessary click. If you
576 // can think of a better way, please implement it.
577 include_once('./addrbook_search_html.php');
578 } else if (isset($attach)) {
579 if (saveAttachedFiles())
580 plain_error_message(_("Could not move/copy file. File not attached"), $color);
581 displayPageHeader($color, $mailbox);
582 showInputForm();
583 } else if (isset($do_delete)) {
584 displayPageHeader($color, $mailbox);
585
586 if (isset($delete) && is_array($delete))
587 {
588 foreach($delete as $index)
589 {
590 unlink ($attachment_dir.$attachments[$index]['localfilename']);
591 unset ($attachments[$index]);
592 }
593 }
594
595 showInputForm();
596 } else {
597 // This handles the default case as well as the error case
598 // (they had the same code) --> if (isset($smtpErrors))
599 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
600 $imapPort, 0);
601 displayPageHeader($color, $mailbox);
602
603 $newmail = true;
604
605 ClearAttachments();
606
607 if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num)
608 getAttachments(0);
609
610 if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num)
611 getAttachments(0);
612
613 newMail();
614 showInputForm();
615 sqimap_logout($imapConnection);
616 }
617
618 function ClearAttachments() {
619 global $attachments, $attachment_dir;
620
621 foreach ($attachments as $info) {
622 if (file_exists($attachment_dir . $info['localfilename'])) {
623 unlink($attachment_dir . $info['localfilename']);
624 }
625 }
626
627 $attachments = array();
628 }
629
630 function getReplyCitation($orig_from) {
631 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
632
633 /* First, return an empty string when no citation style selected. */
634 if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
635 return ('');
636 }
637
638 /* Otherwise, try to select the desired citation style. */
639 switch ($reply_citation_style) {
640 case 'author_said':
641 $start = '';
642 $end = ' ' . _("said") . ':';
643 break;
644 case 'quote_who':
645 $start = '<' . _("quote") . ' ' . _("who") . '="';
646 $end = '">';
647 break;
648 case 'user-defined':
649 $start = $reply_citation_start;
650 $end = $reply_citation_end;
651 break;
652 default: return ('');
653 }
654
655 /* Build and return the citation string. */
656 return ($start . $orig_from . $end . "\n");
657 }
658 ?>